refactor(errors): extract shared errorMessage() helper (PP-uufe) - #2112
Conversation
Replace 21 repetitions of the `error instanceof Error ? error.message : X` idiom with a single pure helper `errorMessage(error, fallback?)` in src/lib/errors.ts. - String-literal fallback sites pass their literal explicitly. - Sites that previously fell back to `String(err)` now call `errorMessage(err)` bare; the helper defaults the fallback to `String(error)` so non-Error throws still surface something readable. - Raw-value fallback sites (`: error` / `: dbError`, logged as structured fields) are intentionally left unconverted — a string-typed helper would discard the object payload the logger serializes. Adds unit coverage in src/lib/errors.test.ts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0131WEJgWBmXWjoZ1qYfLsWJ
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
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: Advanced Run ID: 📒 Files selected for processing (15)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📜 Recent review details🧰 Additional context used🪛 ast-grep (0.45.3)src/lib/rate-limit.ts[warning] 331-338: Avoid logging sensitive data (log-sensitive-data-typescript) 🔇 Additional comments (7)
📝 WalkthroughWalkthroughThe pull request adds the shared ChangesShared Error Formatting
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~12 minutes Change: Refactor Merge Risk: ⚪ Minimal · up to The refactor preserves existing error messages and fallbacks across the updated paths, with focused helper coverage in place. No actionable merge risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Summary
Extracts a single pure helper
errorMessage(error, fallback?)(src/lib/errors.ts) to replace 21 hand-rolled repetitions of theerror instanceof Error ? error.message : Xidiom across the codebase. Addresses the DRY item tracked in PP-uufe (from the PP-ywcr dedup survey).The helper
Design note: the bead proposed a literal
fallback = "Unknown"default. I used an optional fallback that defaults toString(error)instead, because the call sites fell into two families — string-literal fallbacks (: "Unknown",: "Upload failed", …) andString(err)fallbacks. A hard"Unknown"default could not replace theString(err)family without changing behavior; the optional-String()default preserves exact semantics at every site (literal sites pass their literal;String(err)sites callerrorMessage(err)bare). Uses??(not||) so an explicit empty-string fallback is honored.Scope — what was deliberately NOT changed
Four remaining ternaries have a raw-value fallback (
: error/: dbError/: parseError) that is logged into a structurederrfield —logger.ts,report/actions.ts(×2),report/(tabbed)/quick/actions.ts. Astring-typed helper would coerce the object to"[object Object]"and discard the payload the logger serializes, so these are left as-is. Guard expressions (instanceof Error && …) are not the target idiom and are untouched. No behavior changes anywhere — every conversion is 1:1 equivalent to the ternary it replaced.Testing
typecheck,typecheck:tests,lint(oxlint),prettier— all clean.src/lib/errors.test.ts(6 cases) + full unit suite: 2727 pass. The 5 failures insrc/test/unit/scripts/db-target-guards.test.tsare subprocess-spawn timeouts specific to this cloud sandbox — unrelated to this diff (noscripts/files touched) and green in CI.Refs PP-uufe.
🤖 Generated with Claude Code
https://claude.ai/code/session_0131WEJgWBmXWjoZ1qYfLsWJ
Generated by Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests