fix(db): throw on corrupt commands JSON instead of silent empty fallback#1033
Conversation
…ack (coleam00#967) getCodebaseCommands() silently returned {} when the commands column contained corrupt JSON. Callers had no way to distinguish 'no commands' from 'unreadable data', violating fail-fast principles. Now throws a descriptive error with the codebase ID and a recovery hint. The error is still logged for observability before throwing. Adds two test cases: corrupt JSON throws, valid JSON string parses.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughgetCodebaseCommands now surfaces corrupt JSON in the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/db/codebases.ts`:
- Around line 64-69: The catch block that currently swallows the parse error
should log the original error object before throwing the user-facing Error:
update the catch to include the caught error (_err) in the logging call (e.g.,
getLog().error({ codebaseId: id, raw, err: _err },
'db.codebase_commands_json_parse_failed')) so the raw parse exception is
preserved in logs; keep the existing thrown Error message for users but do not
remove or discard _err.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 668a785b-77d0-4e1c-8f37-516a6b5b9f12
📒 Files selected for processing (2)
packages/core/src/db/codebases.test.tspackages/core/src/db/codebases.ts
|
Good catch @coderabbitai — included the original parse error in the log entry (beaacdc). Now |
|
Tip For best results, initiate chat on the files or code changes.
🧠 Learnings usedIf you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|
Gentle ping — any thoughts on this one? Happy to address feedback if needed. Will close in ~7 days if no response to keep things tidy. 🙂 |
beaacdc to
f0892b2
Compare
Fixes #967
Problem
getCodebaseCommands()silently returned{}when thecodebases.commandscolumn contained corrupt JSON. The error was logged but never surfaced to the caller, so a client receiving{}had no way to distinguish "no commands configured" from "commands exist but are unreadable."Fix
Errorinstead of silently returning{}Changes
packages/core/src/db/codebases.ts— replacereturn {}withthrow new Error(...)in the JSON parse catch blockpackages/core/src/db/codebases.test.ts— add two test cases:Validation
bun test— 31 pass, 0 failbun run type-check— all packages cleanbun run lint— no errorsSummary by CodeRabbit