Refactor JSON loading to handle errors safely - #236
Open
krataratha wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Hardens the dev-only scripts/validate-plugins.mjs validation script so JSON parsing/read failures are handled more gracefully and don’t crash the script with uncaught exceptions while validating marketplace.json and per-plugin plugin.json.
Changes:
- Replace
loadJSONwithsafeLoadJSONreturning{ data, error }, and gate validation on load errors. - Improve Ajv error iteration robustness via
validate*.errors ?? []and add defensive optional chaining for plugin traversal / name checks. - Make
ajv-formatsregistration resilient to mixed ESM/CJS export shapes.
Suppressed comments (1)
scripts/validate-plugins.mjs:89
- Same as marketplace.json:
safeLoadJSONmay fail for reasons other than malformed JSON (e.g., read/permission errors), so the error wording here can be misleading.
if (pluginJsonError) {
fail(
`Plugin "${entry.name}": malformed JSON in ${entry.source}/.cursor-plugin/plugin.json (${pluginJsonError})`
);
continue;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+20
to
+25
| const marketplaceSchema = safeLoadJSON( | ||
| resolve(root, "schemas/marketplace.schema.json") | ||
| ); | ||
| const pluginSchema = loadJSON(resolve(root, "schemas/plugin.schema.json")); | ||
| ).data; | ||
| const pluginSchema = safeLoadJSON( | ||
| resolve(root, "schemas/plugin.schema.json") | ||
| ).data; |
Comment on lines
+15
to
+17
| } catch (err) { | ||
| return { data: null, error: err.message }; | ||
| } |
Comment on lines
+50
to
+53
| if (marketplaceJsonError) { | ||
| fail(`marketplace.json is invalid JSON: ${marketplaceJsonError}`); | ||
| process.exit(1); | ||
| } |
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.
Note
Low Risk
Dev-only validation script changes with no runtime product or data-path impact.
Overview
Hardens
scripts/validate-plugins.mjsso invalid JSON no longer crashes the script with an uncaught parse exception.loadJSONis replaced bysafeLoadJSON, which returns{ data, error }. Marketplace and per-pluginplugin.jsonreads now report clear errors (including the parse message) and exit or skip that plugin instead of throwing. Ajv validation loops use?? []onerrors, and the plugin loop uses optional chaining onmarketplace.pluginsandpluginJson.name.Also fixes
ajv-formatsregistration for mixed ESM/CJS exports via(addFormats.default || addFormats)(ajv).Reviewed by Cursor Bugbot for commit 83cc726. Bugbot is set up for automated code reviews on this repo. Configure here.