-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: adding error display feature #436
Conversation
To view this pull requests documentation preview, visit the following URL: docs.page/focustree/starknet.dart~436 Documentation is deployed and generated using docs.page. |
WalkthroughThis pull request modifies error handling and flow control across multiple modules. In the secure store, the decryption method’s try-catch block has been removed, so decryption errors are now unhandled. In the wallet kit package, new error classes and a singleton error handler have been introduced and exported for structured error management. Additionally, the account addition flow has been updated to be asynchronous with improved error checking and conditional navigation in both the provider and UI widget. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant WC as WalletCell (UI)
participant WP as WalletProvider
participant EH as WalletKitErrorHandler
U->>WC: Press "Add Account" button
WC->>WP: Call addAccount(context)
alt Success
WP-->>WC: Complete account addition
WC->>Navigation: Pop modal (if context mounted)
else Error occurs
WP-->>WC: Throws WalletKitError ("Wallet not found", "Wrong password", or "Secret not found")
WC->>EH: Invoke handleError(context, error)
EH-->>WC: Display error message & navigate back
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
🧹 Nitpick comments (1)
packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)
1-9
: Consider enhancing the error class implementation.The error class could benefit from the following improvements:
- Make the class final to prevent inheritance
- Add documentation for the message and code fields
- Consider adding error codes as constants for common errors
+/// Represents errors that occur during wallet operations. +/// +/// The [message] provides a human-readable description of the error. +/// The [code] can be used to identify specific error types programmatically. -class WalletKitError implements Exception { +final class WalletKitError implements Exception { final String message; + /// Optional error code for programmatic error handling. + /// Positive integers are reserved for system use. final int? code; WalletKitError(this.message, {this.code});
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
examples/wallet_app/ios/Podfile.lock
is excluded by!**/*.lock
📒 Files selected for processing (6)
examples/wallet_app/.gitignore
(1 hunks)packages/secure_store/lib/src/password_store.dart
(1 hunks)packages/wallet_kit/lib/errors/index.dart
(1 hunks)packages/wallet_kit/lib/errors/wallet_kit_error.dart
(1 hunks)packages/wallet_kit/lib/wallet_state/wallet_provider.dart
(3 hunks)packages/wallet_kit/lib/widgets/wallet_list.dart
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/wallet_kit/lib/errors/index.dart
🔇 Additional comments (1)
examples/wallet_app/.gitignore (1)
8-8
: LGTM! Appropriate additions for Swift/SPM projects.The new entries
.build/
and.swiftpm/
are standard ignore patterns for Swift and Swift Package Manager projects. These directories contain build artifacts and project-specific metadata that should not be version controlled.Also applies to: 12-12
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/wallet_kit/lib/errors/wallet_kit_error.dart (2)
3-8
: Consider clarifying the purpose and usage of_context
andscaffoldKey
.
Currently, these fields are declared but not utilized. If you plan to display UI-based error handling (e.g., SnackBars, dialogs), integrate theScaffoldState
orBuildContext
inhandleError
, or remove them if they are not needed.
16-19
: Refine logging statement.
The string "WalleeeeetKit Error" appears to contain repeated letters. Consider ensuring consistency before shipping to end users. Also, replacedebugPrint
or a logger package for better debugging control.- print("WalleeeeetKit Error: $error"); + debugPrint("WalletKitError: $error");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
examples/wallet_app/lib/main.dart
(2 hunks)melos_monorepo.iml
(1 hunks)packages/wallet_kit/ios/Flutter/Generated.xcconfig
(1 hunks)packages/wallet_kit/ios/Flutter/flutter_export_environment.sh
(1 hunks)packages/wallet_kit/lib/errors/wallet_kit_error.dart
(1 hunks)packages/wallet_kit/lib/wallet_state/wallet_provider.dart
(3 hunks)packages/wallet_kit/lib/widgets/wallet_list.dart
(1 hunks)packages/wallet_kit/macos/Flutter/ephemeral/Flutter-Generated.xcconfig
(1 hunks)packages/wallet_kit/macos/Flutter/ephemeral/flutter_export_environment.sh
(1 hunks)
✅ Files skipped from review due to trivial changes (4)
- packages/wallet_kit/macos/Flutter/ephemeral/Flutter-Generated.xcconfig
- packages/wallet_kit/ios/Flutter/flutter_export_environment.sh
- packages/wallet_kit/ios/Flutter/Generated.xcconfig
- packages/wallet_kit/macos/Flutter/ephemeral/flutter_export_environment.sh
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/wallet_kit/lib/widgets/wallet_list.dart
🔇 Additional comments (4)
melos_monorepo.iml (1)
7-9
: LGTM! Standard exclusions for Dart/Flutter projects.The added exclusions for
.dart_tool
,.pub
, andbuild
directories follow best practices for Dart/Flutter projects. These directories contain generated files and caches that should not be indexed by the IDE.packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)
22-30
: Good introduction of a custom exception class.
TheWalletKitError
class is straightforward and enables passing both a message and a code. This design simplifies structured error reporting.packages/wallet_kit/lib/wallet_state/wallet_provider.dart (2)
49-49
: Excellent decision to makeaddAccount
asynchronous.
By returningFuture<void>
, external callers can properly await for its completion and handle related exceptions.
63-79
: Enhance error message granularity.
This catch block throws a single “Wrong password” message for all errors. If the issue is that the seed phrase was never created or there's a different decryption error, the user still sees “Wrong password.” Consider passing the original error or differentiating the error cases for more precise feedback.} catch (e) { - final error = WalletKitError("Wrong password"); - WalletKitErrorHandler().handleError(error); + if (e.toString().contains('decrypt')) { + WalletKitErrorHandler().handleError(WalletKitError("Wrong password")); + } else { + WalletKitErrorHandler().handleError(WalletKitError("Failed to add account: ${e.toString()}")); + } }
# Conflicts: # examples/wallet_app/lib/main.dart # packages/wallet_kit/lib/wallet_state/wallet_provider.dart
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
examples/wallet_app/lib/main.dart
(1 hunks)examples/wallet_app/macos/Flutter/GeneratedPluginRegistrant.swift
(1 hunks)packages/wallet_kit/lib/errors/wallet_kit_error.dart
(1 hunks)packages/wallet_kit/lib/wallet_state/wallet_provider.dart
(3 hunks)packages/wallet_kit/lib/widgets/wallet_list.dart
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/wallet_kit/lib/widgets/wallet_list.dart
- examples/wallet_app/lib/main.dart
- packages/wallet_kit/lib/wallet_state/wallet_provider.dart
🔇 Additional comments (2)
examples/wallet_app/macos/Flutter/GeneratedPluginRegistrant.swift (1)
1-16
: Skip reviewing generated file.This is an auto-generated file that should not be manually edited. The changes appear to be automatically generated, likely due to a plugin update.
packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)
18-26
: LGTM! Well-structured error class implementation.The
WalletKitError
class is well-designed with:
- Clear separation of required and optional parameters
- Clean toString() implementation for error formatting
- Proper Exception interface implementation
void handleError(WalletKitError error, BuildContext context) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text('Failed to add account: $error')), | ||
); | ||
Navigator.of(context).pop(); | ||
} |
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.
🛠️ Refactor suggestion
Make error handling more robust and generic.
The current implementation has two issues:
- The error message is hardcoded to "Failed to add account", which may not be appropriate for all error scenarios.
- Unconditionally popping the navigation stack could crash the app if called from the root route.
Apply this diff to make the error handling more robust:
void handleError(WalletKitError error, BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(content: Text('Failed to add account: $error')),
+ SnackBar(content: Text('$error')),
);
- Navigator.of(context).pop();
+ if (Navigator.of(context).canPop()) {
+ Navigator.of(context).pop();
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
void handleError(WalletKitError error, BuildContext context) { | |
ScaffoldMessenger.of(context).showSnackBar( | |
SnackBar(content: Text('Failed to add account: $error')), | |
); | |
Navigator.of(context).pop(); | |
} | |
void handleError(WalletKitError error, BuildContext context) { | |
ScaffoldMessenger.of(context).showSnackBar( | |
SnackBar(content: Text('$error')), | |
); | |
if (Navigator.of(context).canPop()) { | |
Navigator.of(context).pop(); | |
} | |
} |
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.
Thanks for your contributions!
I really like to have a default error handler but I'm concerned about how a developer can easily customized this behavior without wallet_kit source code modifications.
Why not using notifier instead of a callback ?
packages/wallet_kit/macos/Flutter/ephemeral/Flutter-Generated.xcconfig
Outdated
Show resolved
Hide resolved
packages/wallet_kit/macos/Flutter/ephemeral/flutter_export_environment.sh
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 0
♻️ Duplicate comments (1)
packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)
16-20
:⚠️ Potential issueMake error display and navigation handling more robust.
The current implementation has two issues that should be addressed:
- The error message follows a format that may not be ideal for all scenarios, with a potentially redundant prefix.
- Unconditionally popping the navigation stack could crash the app if called from a route that can't be popped.
Apply this diff to make the error handling more robust:
void handleError( BuildContext context, WalletKitError error, String? message, ) { ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('${message ?? "error"}: $error')), + SnackBar(content: Text(message != null ? '$message: $error' : '$error')), ); - Navigator.of(context).pop(); + if (Navigator.of(context).canPop()) { + Navigator.of(context).pop(); + } }
🧹 Nitpick comments (2)
packages/wallet_kit/lib/errors/wallet_kit_error.dart (2)
11-15
: Consider providing additional context handling options.The error handler only supports showing a snackbar and popping the navigation stack, which may not be appropriate for all error scenarios.
Consider adding flexible options to customize the error handling behavior:
void handleError( BuildContext context, WalletKitError error, String? message, + {bool popNavigation = true, + Duration snackBarDuration = const Duration(seconds: 4)} ) { ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('${message ?? "error"}: $error')), + SnackBar( + content: Text(message != null ? '$message: $error' : '$error'), + duration: snackBarDuration, + ), ); - Navigator.of(context).pop(); + if (popNavigation && Navigator.of(context).canPop()) { + Navigator.of(context).pop(); + } }
3-21
: Consider exposing the singleton instance directly.The Singleton pattern implementation is good, but accessing it requires calling the constructor function, which might be slightly less intuitive than directly accessing a static instance.
Consider exposing the instance directly for easier access:
class WalletKitErrorHandler { static final WalletKitErrorHandler _instance = WalletKitErrorHandler._internal(); + static WalletKitErrorHandler get instance => _instance; WalletKitErrorHandler._internal(); factory WalletKitErrorHandler() => _instance; // rest of the class } // Usage would then be: // WalletKitErrorHandler.instance.handleError(...) instead of WalletKitErrorHandler().handleError(...)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/wallet_kit/lib/errors/wallet_kit_error.dart
(1 hunks)packages/wallet_kit/lib/wallet_state/wallet_provider.dart
(2 hunks)packages/wallet_kit/lib/widgets/wallet_list.dart
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/wallet_kit/lib/wallet_state/wallet_provider.dart
- packages/wallet_kit/lib/widgets/wallet_list.dart
🔇 Additional comments (1)
packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)
23-32
: LGTM! Well-structured error class implementation.The
WalletKitError
class is well-designed with:
- Proper implementation of the Exception interface
- Good error formatting with optional code inclusion
- Clear constructor definition
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.
I have created the following issue: #475 to track the remaining customization issue.
Summary by CodeRabbit
New Features
Bug Fixes