fix: use JSON5 fallback for plugin manifest parsing (#57734) [AI-assisted]#57784
fix: use JSON5 fallback for plugin manifest parsing (#57734) [AI-assisted]#57784singleGanghood wants to merge 1 commit into
Conversation
Greptile SummaryThis PR makes a minimal, targeted fix to replace Key changes:
The change is well-scoped: only the read path for third-party plugin manifests is relaxed; config-file output ( Confidence Score: 5/5Safe to merge — the fix is minimal, the utility is already battle-tested in the config read path, and new tests cover all JSON5 extensions plus error cases. No logic errors, no security concerns, no missing error-handling paths. Both file descriptors are still closed in finally blocks. The parseJsonWithJson5Fallback utility tries standard JSON.parse first (performance unchanged for well-formed manifests) and only falls back to JSON5.parse on failure. All remaining review findings are P2 or lower. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/plugins/manifest.ts | Single-line swap of JSON.parse for parseJsonWithJson5Fallback; error handling and fd cleanup unchanged. |
| src/plugins/bundle-manifest.ts | Same single-line swap; try/catch/finally structure preserved correctly. |
| src/plugins/manifest.test.ts | New test file covering all JSON5 extensions and every error path for loadPluginManifest. |
| src/plugins/bundle-manifest.test.ts | Extended with three JSON5 fallback tests (trailing commas, comments, unquoted keys) for loadBundleManifest. |
Reviews (1): Last reviewed commit: "fix: use JSON5 fallback for plugin manif..." | Re-trigger Greptile
25111aa to
e0e52be
Compare
…[AI-assisted] Plugin installation fails with 'Config validation failed' when a third-party plugin's openclaw.plugin.json contains JSON5 syntax (trailing commas, comments, unquoted keys). Replace strict JSON.parse() with parseJsonWithJson5Fallback() in manifest.ts and bundle-manifest.ts to tolerate non-standard JSON in plugin manifests.
e0e52be to
ef9a064
Compare
fix: use JSON5 fallback for plugin manifest parsing (#57734) [AI-assisted]
Plugin installation fails with 'Config validation failed' when a third-party plugin's openclaw.plugin.json contains JSON5 syntax (trailing commas, comments, unquoted keys). Replace strict JSON.parse() with parseJsonWithJson5Fallback() in manifest.ts and bundle-manifest.ts to tolerate non-standard JSON in plugin manifests.
Summary
manifest.tsandbundle-manifest.tsuse strictJSON.parse()to read plugin manifest files (openclaw.plugin.json). When a third-party plugin ships a manifest with JSON5 syntax (trailing commas, comments, unquoted property names), parsing fails withSyntaxError: Expected double-quoted property name in JSON at position 8912 (line 219 column 5), which propagates throughmanifest-registry.ts→validation.ts→io.tsand surfaces asConfig validation failed.JSON.parse()with the existing project utilityparseJsonWithJson5Fallback()(fromsrc/utils/parse-json-compat.ts) in bothmanifest.tsandbundle-manifest.ts. This function first attempts standardJSON.parse()and, on failure, falls back toJSON5.parse(), tolerating trailing commas, comments, and unquoted keys.io.ts/JSON.stringify) is untouched — OpenClaw's own config output remains strict JSON. Only the reading of third-party plugin manifest files is relaxed.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
manifest.ts:263andbundle-manifest.ts:120use strictJSON.parse()to parse plugin manifest files. The JSON spec does not allow trailing commas, comments, or unquoted keys, but many real-world tool ecosystems (VS Code extensions, TypeScript configs, etc.) commonly emit JSON5-compatible files. When@vectorize-io/hindsight-openclawshipped anopenclaw.plugin.jsonwith such syntax,JSON.parse()threw aSyntaxErrorat line 219.parseJsonWithJson5Fallback()for config reading (src/utils/parse-json-compat.ts) but it was not applied to plugin manifest loading.parseJsonWithJson5Fallbackutility was introduced forconfig/io.tsto handle user-edited config files; plugin manifests were overlooked because they were assumed to always be machine-generated strict JSON.@vectorize-io/hindsight-openclaw) published a manifest with trailing commas.JSON.stringifyinio.ts:2185) was confirmed to always produce valid JSON — the issue is exclusively on the read path for plugin manifests.Regression Test Plan (if applicable)
src/plugins/manifest.test.ts(new),src/plugins/bundle-manifest.test.ts(extended)loadPluginManifestandloadBundleManifestsucceed when the manifest file contains trailing commas, single-line/block comments, or unquoted property names.bundle-manifest.test.tsexisted but only tested strict JSON inputs.User-visible / Behavior Changes
openclaw.plugin.jsonmanifest contains JSON5-compatible syntax (trailing commas, comments, unquoted keys).JSON.parseandJSON5.parsemust fail for an error to surface).Diagram (if applicable)