Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when SDK is used and not initialized #114

Merged
merged 7 commits into from
Feb 27, 2025

Conversation

rohan-agarwal-coinbase
Copy link
Contributor

What changed? Why?

  • Right now when a user forgets to call Coinbase.configure, they see an unclear error message because the apiClients aren't defined. This PR uses the proxy pattern in javascript to intercept getting the apiClients, and returns a clear message to the user.

Notes to reviewers

Formatting/linting fixed a few unrelated test files so they can be ignored.

Testing

  • Added a unit test to confirm error behavior when not initialized. Updated conftest for global test setup to mock the APIClients - this was needed for all existing tests to succeed with the new behavior.
  • E2E testing, both with and without Coinbase.configure, have expected behavior.

Here's how it looks:

❯ python test_smart_wallet.py 
Traceback (most recent call last):
  File "/Users/rohanagarwal/code/cdp-sdk-python/test_smart_wallet.py", line 68, in <module>
    test_smart_wallet_operations()
  File "/Users/rohanagarwal/code/cdp-sdk-python/test_smart_wallet.py", line 15, in test_smart_wallet_operations
    smart_wallet = SmartWallet.create(account=owner)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rohanagarwal/code/cdp-sdk-python/cdp/smart_wallet.py", line 61, in create
    model = Cdp.api_clients.smart_wallets.create_smart_wallet(create_smart_wallet_request)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rohanagarwal/code/cdp-sdk-python/cdp/cdp.py", line 38, in __getattr__
    raise UninitializedSDKError()
cdp.errors.UninitializedSDKError: Coinbase SDK has not been initialized. Please initialize by calling either:

- Cdp.configure(api_key_name='...', private_key='...')
- Cdp.configure_from_json(file_path='/path/to/api_keys.json')

If needed, register for API keys at https://portal.cdp.coinbase.com/ or view the docs at https://docs.cdp.coinbase.com/wallet-api/docs/welcome

Qualified Impact

@rohan-agarwal-coinbase rohan-agarwal-coinbase changed the title Improve error message when SDK is used and not initalized Improve error message when SDK is used and not initialized Feb 27, 2025
alex-stone
alex-stone previously approved these changes Feb 27, 2025
@cb-heimdall
Copy link

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@rohan-agarwal-coinbase rohan-agarwal-coinbase merged commit ed55c91 into v0.21.0 Feb 27, 2025
8 checks passed
rohan-agarwal-coinbase added a commit that referenced this pull request Feb 28, 2025
* Improve error message when SDK is used and not initialized (#114)

* Update UserOperation status to support string comparison (#115)

* Preparing v0.21.0 release (#116)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants