Skip to content

Conversation

isaacroldan
Copy link
Contributor

@isaacroldan isaacroldan commented Oct 2, 2025

WHY are these changes introduced?

To improve JSON parsing error handling across the CLI, providing more helpful error messages when JSON parsing fails.

WHAT is this pull request doing?

  • Adds a new parseJSON utility function that safely parses JSON strings with helpful error messages
  • Includes comprehensive tests for the new function covering various scenarios
  • Replaces direct JSON.parse() calls in the node-package-manager module with the new utility

How to test your changes?

  1. Try parsing invalid JSON using the new utility:

    import {parseJSON} from './json.js'
    
    // Should throw a helpful AbortError
    parseJSON('{"invalid": json}', 'config.json')
  2. Run the test suite for the new functionality:

    pnpm test packages/cli-kit/src/public/common/json.test.ts

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@isaacroldan isaacroldan force-pushed the 10-02-handle_malformed_package.json_errors branch from 6cc6f39 to 089d812 Compare October 2, 2025 11:07
Copy link
Contributor

github-actions bot commented Oct 2, 2025

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/public/common/json.d.ts
/**
 * Safely parse JSON with helpful error messages.
 *
 * @param jsonString - The JSON string to parse.
 * @param context - Optional context about what's being parsed (e.g., file path, "API response").
 * @returns The parsed JSON object.
 * @throws AbortError if JSON is malformed.
 *
 * @example
 * // Parse with context
 * const data = parseJSON(jsonString, '/path/to/config.json')
 *
 * @example
 * // Parse without context
 * const data = parseJSON(jsonString)
 */
export declare function parseJSON<T = unknown>(jsonString: string, context?: string): T;

Existing type declarations

We found no diffs with existing type declarations

Copy link
Contributor

github-actions bot commented Oct 2, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.77% (+0.03% 🔼)
13733/17434
🟡 Branches
72.48% (+0.02% 🔼)
6691/9232
🟡 Functions
78.78% (+0% 🔼)
3524/4473
🟡 Lines
79.11% (+0.03% 🔼)
12983/16411
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / json.ts
100% 75% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / conf-store.ts
100%
82.22% (-2.22% 🔻)
100% 100%
🔴
... / environment.ts
40% (-5% 🔻)
41.18%
50% (-10% 🔻)
42.11% (-5.26% 🔻)

Test suite run success

3343 tests passing in 1385 suites.

Report generated by 🧪jest coverage report action from 089d812

@isaacroldan isaacroldan marked this pull request as ready for review October 2, 2025 11:13
@isaacroldan isaacroldan requested a review from a team as a code owner October 2, 2025 11:14
Copy link
Contributor

github-actions bot commented Oct 2, 2025

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run pnpm changeset add to track your changes and include them in the next release CHANGELOG.

Caution

DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release.

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.

1 participant