Skip to content

fix(tools): surface async errors in minifyProtoJson CLI - #9913

Draft
quirogas wants to merge 1 commit into
googleapis:mainfrom
quirogas:fix/tools-minify-proto-json-exit-code
Draft

quirogas wants to merge 1 commit into
googleapis:mainfrom
quirogas:fix/tools-minify-proto-json-exit-code

Conversation

@quirogas

Copy link
Copy Markdown
Contributor

Description

Handles rejected promises in minifyProtoJson so CLI failures exit non-zero.

Impact

Prevents build scripts from silently ignoring proto minification errors.

Changes

  • Catch rejected promises from main(process.argv[2]) in core/packages/tools/src/minify.ts and core/packages/tools/bin/minifyProtoJson.js, logging errors and setting process.exitCode = 1.
  • Remove the @typescript-eslint/no-floating-promises lint suppression in src/minify.ts.
  • Add a unit test verifying bin/minifyProtoJson.js exits with status 1 when minification fails.

Testing

  • Ran unit tests and linter in core/packages/tools (pnpm --dir core/packages/tools test and pnpm --dir core/packages/tools run lint).

Alternatives

  • Leaving main(process.argv[2]) unawaited risks silent exit code discrepancies when a target directory or proto JSON file is missing or malformed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the minify CLI tools to properly catch execution errors and set a non-zero exit code, and adds a test to verify this behavior. A review comment suggests improving the test's path resolution for the CLI script to ensure it works reliably in both compiled and source environments.

Comment on lines +66 to +72
const cliPath = path.join(
__dirname,
'..',
'..',
'bin',
'minifyProtoJson.js',
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The relative path resolution using ../../bin/minifyProtoJson.js assumes the test is always executed from the compiled build/test directory. If the tests are run directly from the source directory (e.g., using ts-node or tsx during development), __dirname will be core/packages/tools/test, and going up two levels will resolve to core/packages/bin/minifyProtoJson.js which does not exist.

To make this robust across both compiled and source environments, consider dynamically resolving the path based on whether __dirname contains build (or dist), or use process.cwd() if the tests are guaranteed to run from the package root.

    const cliPath = path.resolve(
      __dirname,
      __dirname.includes('build')
        ? '../../bin/minifyProtoJson.js'
        : '../bin/minifyProtoJson.js'
    );

This branch has not been deployed

No deployments
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