test(account-abstraction): Add comprehensive error handling tests#160
test(account-abstraction): Add comprehensive error handling tests#160martinvibes wants to merge 1 commit intoancore-org:mainfrom
Conversation
- Add unit tests for all typed error classes (AccountContractError, AlreadyInitializedError, NotInitializedError, InvalidNonceError, UnauthorizedError, SessionKeyNotFoundError, SessionKeyExpiredError, InsufficientPermissionError, ContractInvocationError) - Add tests for CONTRACT_ERROR_MESSAGES constant validation - Add tests for CONTRACT_ERROR_CODES mapping and error instantiation - Add tests for mapContractError function with various contract error scenarios - Export error classes and utilities from main index file for public API access - Ensure proper error inheritance chain and code assignment across all error types
|
@martinvibes Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
📝 WalkthroughWalkthroughTwo new error classes ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/account-abstraction/src/errors.ts (1)
119-125:⚠️ Potential issue | 🟠 MajorAdd string-path mapping for
SessionKeyNotFoundErrorto keep typed mapping complete.
SessionKeyNotFoundErrorexists, butmapContractErrordoes not map"Session key not found"messages when no numeric code is present (Line 155 onward). That path currently degrades toContractInvocationError.🔧 Proposed fix
export const CONTRACT_ERROR_MESSAGES = { ALREADY_INITIALIZED: 'Already initialized', NOT_INITIALIZED: 'Not initialized', INVALID_NONCE: 'Invalid nonce', + SESSION_KEY_NOT_FOUND: 'Session key not found', SESSION_KEY_EXPIRED: 'Session key expired', INSUFFICIENT_PERMISSION: 'Insufficient permission', } as const; @@ export function mapContractError(message: string, raw?: unknown): AccountContractError { @@ + if ( + message.toLowerCase().includes('session key not found') || + message.toLowerCase().includes('sessionkeynotfound') + ) { + return new SessionKeyNotFoundError(); + } if ( message.toLowerCase().includes('session key expired') || message.toLowerCase().includes('sessionkeyexpired') ) {Also applies to: 155-176
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/account-abstraction/src/errors.ts` around lines 119 - 125, The mapping for the string error path "Session key not found" is missing, so add a CONTRACT_ERROR_MESSAGES entry (e.g. SESSION_KEY_NOT_FOUND: 'Session key not found') and update mapContractError to handle that string path by returning/throwing the SessionKeyNotFoundError instead of falling back to ContractInvocationError; locate CONTRACT_ERROR_MESSAGES and the mapContractError function to make these coordinated changes so the typed mapping includes the session-key-not-found branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/account-abstraction/src/errors.ts`:
- Around line 119-125: The mapping for the string error path "Session key not
found" is missing, so add a CONTRACT_ERROR_MESSAGES entry (e.g.
SESSION_KEY_NOT_FOUND: 'Session key not found') and update mapContractError to
handle that string path by returning/throwing the SessionKeyNotFoundError
instead of falling back to ContractInvocationError; locate
CONTRACT_ERROR_MESSAGES and the mapContractError function to make these
coordinated changes so the typed mapping includes the session-key-not-found
branch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7853ad57-b58f-4d42-8535-8a2e93774d88
📒 Files selected for processing (3)
packages/account-abstraction/src/__tests__/errors.test.tspackages/account-abstraction/src/errors.tspackages/account-abstraction/src/index.ts
|
@martinvibes please resolve conflicts |
closes #114
Summary by CodeRabbit
Release Notes
New Features
SessionKeyExpiredErrorexception to handle session key expiration scenarios.InsufficientPermissionErrorexception to handle permission denial scenarios.CONTRACT_ERROR_CODESfor direct programmatic contract error code mapping and resolution.Tests