fix: clear error for balance without address; print commander errors once (fixes #498) - #501
Conversation
…once (fixes #498) - Make the balance address argument required so `offckb balance` prints `error: missing required argument 'toAddress'` instead of leaking the SDK's `Unknown address format undefined`. - Only emit commander errors through logger.failure in JSON mode; in human mode commander's writeErr already printed the line once, so re-emitting duplicated every commander error on stderr.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe ChangesCLI error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized CLI change improves missing-argument validation and prevents duplicate error output; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
Fixes #498
Bug 1:
offckb balancewithout address →Unknown address format undefinedbalance [toAddress]declared the address optional (src/cli.ts:237). When omitted,undefinedflowed intobalanceOf()→CKB.balance(undefined)→ccc.Address.fromString(undefined), leaking the low-levelUnknown address format undefined.Fix: make the argument required (
balance <toAddress>). Commander now emits a clearerror: missing required argument 'toAddress'on stderr and exits 1.Bug 2: commander errors printed twice on stderr
configureCommanderErrors()setsexitOverride()and writes the error line once viawriteErr. TherunCli()catch block then calledlogger.failure(code, message), which in non-JSON mode routed the same message through the winston console transport to stderr again — every commander error line was emitted twice.Fix: only call
logger.failureforCommanderErrorin JSON mode (wherewriteErris suppressed and the structured record is the single emission). In human mode commander'swriteErralready printed the line exactly once.Verified on a local build:
Tests
Added
tests/cli-errors.test.ts(5 cases): missing-argument error printed once, unknown-option printed once, invalid option value printed once, single structured record in--jsonmode, and a validbalance <addr>invocation still reachesbalanceOf. All 4 regression cases fail on the pre-fix code and pass after.Changeset included (
@offckb/clipatch).