-
Notifications
You must be signed in to change notification settings - Fork 36
fix: added trycatch for safe provider access #476
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
Conversation
|
| Name | Type |
|---|---|
| @reown/appkit-core-react-native | Patch |
| @reown/appkit-react-native | Patch |
| @reown/appkit-ui-react-native | Patch |
| @reown/appkit-common-react-native | Patch |
| @reown/appkit-ethers-react-native | Patch |
| @reown/appkit-solana-react-native | Patch |
| @reown/appkit-bitcoin-react-native | Patch |
| @reown/appkit-wagmi-react-native | Patch |
| @reown/appkit-coinbase-react-native | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances error handling in the AppKit library to prevent crashes when provider access fails during session restoration or app restarts. The changes add try-catch blocks around provider access methods to gracefully handle cases where providers are not yet initialized.
- Added try-catch error handling to
getProvidermethod in AppKit class - Added try-catch error handling to
useProviderhook - Updated documentation to clarify return values when providers are unavailable
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/appkit/src/AppKit.ts | Added try-catch block to getProvider method with error logging and updated JSDoc |
| packages/appkit/src/hooks/useProvider.ts | Added try-catch block to useProvider hook to handle provider initialization errors |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Claude finished @ignaciosantise's task —— View job Code Review CompleteTasks
Review Findings1. Silent Error Swallowing in
|
|
|
@claude review |
|
Claude finished @ignaciosantise's task —— View job 🔄 Incremental Review: Tasks
Review Findings✅ Resolved Issues from Previous Review
🔴 Issues Still Present
📝 SummaryThe latest commits successfully addressed the two main code quality issues:
The error handling implementation now follows project conventions consistently. The remaining action item is to add a changeset for proper version tracking. No new issues found in the latest commits. The code improvements are solid and align with React Native and TypeScript best practices. |



This pull request improves the resilience of provider access in the
AppKitlibrary by handling cases where the provider may not be initialized, such as during session restoration or app restarts. The main changes add error handling and clarify return values to prevent crashes and improve stability.Error handling and stability improvements:
getProvidermethod inAppKitto returnnullif the provider is not available or not yet initialized, and added a try/catch block to handle errors gracefully and log them during session restoration scenarios. [1] [2]useProviderhook to wrap provider access in a try/catch block, returningundefinedfor the provider and provider type if the provider is not initialized, preventing errors during session restoration.Note
Wrap provider access in try/catch, return null/undefined when uninitialized, and log errors in
AppKit.getProvideranduseProvider.packages/appkit/src/AppKit.tsgetProvider: return type clarified toT | null; now guards missing connection/adapter and wrapsconnector.getProvider()in try/catch, returningnulland logging on errors.packages/appkit/src/hooks/useProvider.tsuseProvider: adds adapter presence check; wrapsadapter.getProvider()in try/catch, returning{ provider: undefined, providerType: undefined }on failure and logging the error.Written by Cursor Bugbot for commit 9c9885f. This will update automatically on new commits. Configure here.