Skip to content

Refactor JSON loading to handle errors safely - #236

Open
krataratha wants to merge 1 commit into
cursor:mainfrom
krataratha:patch-1
Open

Refactor JSON loading to handle errors safely#236
krataratha wants to merge 1 commit into
cursor:mainfrom
krataratha:patch-1

Conversation

@krataratha

@krataratha krataratha commented Aug 20, 2026

Copy link
Copy Markdown

Note

Low Risk
Dev-only validation script changes with no runtime product or data-path impact.

Overview
Hardens scripts/validate-plugins.mjs so invalid JSON no longer crashes the script with an uncaught parse exception.

loadJSON is replaced by safeLoadJSON, which returns { data, error }. Marketplace and per-plugin plugin.json reads now report clear errors (including the parse message) and exit or skip that plugin instead of throwing. Ajv validation loops use ?? [] on errors, and the plugin loop uses optional chaining on marketplace.plugins and pluginJson.name.

Also fixes ajv-formats registration 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.

Copilot AI lite review requested due to automatic review settings August 20, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 loadJSON with safeLoadJSON returning { 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-formats registration resilient to mixed ESM/CJS export shapes.
Suppressed comments (1)

scripts/validate-plugins.mjs:89

  • Same as marketplace.json: safeLoadJSON may 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants