fix: parse OpenClaw config with JSON5 for model catalog#210
Conversation
📝 WalkthroughWalkthroughThe changes add support for JSON5 format (which allows comments and trailing commas) when parsing OpenClaw configuration files. This involves adding the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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.
🧹 Nitpick comments (1)
server/routes/gateway.ts (1)
163-163: Unify OpenClaw config parsing across routes to prevent split behavior.
/api/gateway/modelsparses~/.openclaw/openclaw.jsonwithJSON5.parse, whileserver/routes/channels.tsusesJSON.parseon the same file and silently returns[]on failure. If the config file contains JSON5 syntax (e.g., comments, trailing commas), gateway succeeds but channels silently fails, producing inconsistent UI state (models load, channels disappear). Consider extracting a shared config-reader helper using a consistent parser strategy.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/routes/gateway.ts` at line 163, The OpenClaw config is parsed inconsistently (gateway.ts uses JSON5.parse while channels.ts uses JSON.parse and swallows errors); extract a shared helper (e.g., readOpenClawConfig or parseOpenClawConfig) that reads the ~/.openclaw/openclaw.json and consistently uses JSON5.parse to return an OpenClawConfig (or a clear fallback) and import it from both server/routes/gateway.ts and server/routes/channels.ts; update channels.ts to call this helper instead of JSON.parse, ensure it does not silently return [] on parse error (log the error via the existing logger and return a safe default), and keep the helper's API typed so callers (models route and channels route) handle the same shape consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@server/routes/gateway.ts`:
- Line 163: The OpenClaw config is parsed inconsistently (gateway.ts uses
JSON5.parse while channels.ts uses JSON.parse and swallows errors); extract a
shared helper (e.g., readOpenClawConfig or parseOpenClawConfig) that reads the
~/.openclaw/openclaw.json and consistently uses JSON5.parse to return an
OpenClawConfig (or a clear fallback) and import it from both
server/routes/gateway.ts and server/routes/channels.ts; update channels.ts to
call this helper instead of JSON.parse, ensure it does not silently return [] on
parse error (log the error via the existing logger and return a safe default),
and keep the helper's API typed so callers (models route and channels route)
handle the same shape consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9e86d025-571f-4867-8cc0-7523daa227d2
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
package.jsonserver/routes/gateway.test.tsserver/routes/gateway.ts
Summary
Fixes the false-positive header warning from #209.
Closes #209.
What changed
/api/gateway/modelsfromJSON.parsetoJSON5.parsejson5as a runtime dependencyWhy
Nerve v1.5.2 started reading configured models directly from the active OpenClaw config. If
openclaw.jsonused JSON5-style syntax (comments, unquoted keys, trailing commas), Nerve could fail to parse it and show:even though OpenClaw itself was working normally.
Verification
npm test -- server/routes/gateway.test.tsnpm run build:serverAlso verified live:
Summary by CodeRabbit
New Features
Tests