fix: add error logging to silent catch blocks in API handlers#388
fix: add error logging to silent catch blocks in API handlers#388andreabadesso merged 2 commits intomasterfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThree API handlers in the wallet service now include error logging in their exception-handling paths. When operations fail during register, transaction proposal destruction, and wallet ID proxy handling, the code instantiates a default logger and emits error details before returning the same error responses. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/wallet-service/src/commons.ts (1)
555-563: Initialize logger only in thecatchpath.Line 555 creates a logger for every invocation, even when
walletIdextraction succeeds. Move it intocatch(same pattern used inpushRegisterandtxProposalDestroy) to avoid unnecessary work on the hot path.Proposed diff
export const walletIdProxyHandler = (handler: WalletProxyHandler): APIGatewayProxyHandler => ( async (event, context) => { - const logger = createDefaultLogger(); let walletId: string; try { walletId = event.requestContext.authorizer.principalId; // validate walletId? } catch (e) { + const logger = createDefaultLogger(); logger.error('Failed to extract walletId from authorization context', { error: e.message, }); return {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/wallet-service/src/commons.ts` around lines 555 - 563, The logger is being created unconditionally which wastes work on the hot path; move the createDefaultLogger() call into the catch block that handles extraction of walletId so the logger is only initialized when an error occurs. Locate the walletId extraction (walletId = event.requestContext.authorizer.principalId) in commons.ts and replace the eager const logger = createDefaultLogger() with creating the logger inside the catch where logger.error(...) is called (mirror the pattern used in pushRegister and txProposalDestroy), and ensure the catch still logs e.message and any context after creating the logger.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/wallet-service/src/commons.ts`:
- Around line 555-563: The logger is being created unconditionally which wastes
work on the hot path; move the createDefaultLogger() call into the catch block
that handles extraction of walletId so the logger is only initialized when an
error occurs. Locate the walletId extraction (walletId =
event.requestContext.authorizer.principalId) in commons.ts and replace the eager
const logger = createDefaultLogger() with creating the logger inside the catch
where logger.error(...) is called (mirror the pattern used in pushRegister and
txProposalDestroy), and ensure the catch still logs e.message and any context
after creating the logger.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: edbe1d2a-93fb-4cf1-b002-9f6cb17664f2
📒 Files selected for processing (3)
packages/wallet-service/src/api/pushRegister.tspackages/wallet-service/src/api/txProposalDestroy.tspackages/wallet-service/src/commons.ts
Motivation
Following up on #387, an audit of the codebase revealed several other API handlers with catch blocks that silently swallow errors without any logging, making it impossible to diagnose failures in production.
Acceptance Criteria
walletIdProxyHandlerincommons.tslogs errors when authorization context extraction failstxProposalDestroyhandler logs errors when the DB transaction (cancel + release UTXOs) failspushRegisterhandler logs errors when the DB transaction (remove + register device) failsChecklist
master, confirm this code is production-ready and can be included in future releases as soon as it gets merged🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes