fix(config): tolerate trailing commas in micode.json and warn on parse errors#30
Closed
nitoba wants to merge 2 commits intovtemian:mainfrom
Closed
fix(config): tolerate trailing commas in micode.json and warn on parse errors#30nitoba wants to merge 2 commits intovtemian:mainfrom
nitoba wants to merge 2 commits intovtemian:mainfrom
Conversation
…e errors Hand-edited JSON configs commonly include trailing commas, which causes JSON.parse to throw. The catch block silently returns null, so all user overrides are lost with zero feedback. - Add stripTrailingCommas helper using a string-safe regex that skips quoted values (prevents corrupting strings like "hello, }") - Apply to all three JSON.parse sites (opencode.json, micode.json, model context limits) - Distinguish file-not-found (silent) from parse errors in loadMicodeConfig — log a clear warning via log.warn so users know their config was ignored https://claude.ai/code/session_019WCTQeKgwFg1RG2rrBDjas
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/config-loader.ts">
<violation number="1" location="src/config-loader.ts:184">
P2: The warning message in loadMicodeConfig conflates read errors with parse errors; any non-ENOENT filesystem error is logged as “Failed to parse micode.json,” which is misleading and can send users to fix JSON when the issue is permissions/path/I/O.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Split the single try/catch in loadMicodeConfig into two separate try/catch blocks: one for the readFile call and one for JSON.parse and validation. Filesystem errors (permissions, I/O, etc.) now log "Failed to read micode.json" while JSON syntax errors continue to log "Failed to parse micode.json", so users get accurate guidance on what actually went wrong.
Author
|
No fix needed. The error handling is already correctly separate @cubic-dev-ai |
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
Hand-edited JSON configs commonly include trailing commas (e.g. "compactionThreshold": 0.8,). JSON.parse rejects this and throws. The catch block was silently returning null, causing all user overrides to be lost with zero feedback — users had no way to know their micode.json was being ignored.
Approach
Instead of adding a JSONC parser dependency, a lightweight regex strips trailing commas before parsing. The regex uses alternation ("..." | ,\s*[]}]) to match quoted strings first and return them unchanged, so values containing , } or , ] are never corrupted.
For truly invalid JSON (beyond trailing commas), the error is now surfaced via log.warn with the parse error message, while file-not-found remains silent as expected.
Test plan
Summary by cubic
Tolerates trailing commas in JSON configs and warns on read/parse errors so user overrides aren’t silently ignored. Applies to
micode.json,opencode.json, and model context limits.opencode.json,micode.json, and model context limits.loadMicodeConfig, keep file-not-found silent; warn on read failures (“Failed to read micode.json”) and on parse errors (“Failed to parse micode.json”).Written for commit ef676ba. Summary will update on new commits.