Skip to content

Specify oclif exitcode in cli errors #6768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-crabs-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/cli': patch
---

Correct error exit codes
5 changes: 4 additions & 1 deletion integration-tests/tests/api/target/usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test.concurrent(
},
]);
expect(collectResult.status).toEqual(200);
await waitFor(8000);
await waitFor(10_000);

// should be breaking because the field is used now
const usedCheckResult = await readToken
Expand Down Expand Up @@ -123,6 +123,9 @@ test.concurrent(
expect(op.name).toMatch('ping');
expect(op.percentage).toBeGreaterThan(99);
},
{
timeout: 15_000,
},
);

test.concurrent(
Expand Down
20 changes: 10 additions & 10 deletions integration-tests/tests/cli/__snapshots__/schema.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ http://__URL__
exports[`FEDERATION > publish validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
Expand All @@ -173,7 +173,7 @@ stdout--------------------------------------------:
exports[`FEDERATION > publish validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
Expand All @@ -198,7 +198,7 @@ stdout--------------------------------------------:
exports[`FEDERATION > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
3
stderr--------------------------------------------:
› Error: The SDL is not valid at line 1, column 1:
› Syntax Error: Unexpected Name "iliketurtles". [301]
Expand Down Expand Up @@ -274,7 +274,7 @@ stdout--------------------------------------------:
exports[`FEDERATION > schema:publish should see Invalid Token error when token is invalid > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: A valid registry token is required to perform the action. The
› registry token used does not exist or has been revoked. [106]
Expand Down Expand Up @@ -461,7 +461,7 @@ stdout--------------------------------------------:
exports[`SINGLE > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
3
stderr--------------------------------------------:
› Error: The SDL is not valid at line 1, column 1:
› Syntax Error: Unexpected Name "iliketurtles". [301]
Expand Down Expand Up @@ -542,7 +542,7 @@ stdout--------------------------------------------:
exports[`SINGLE > schema:publish should see Invalid Token error when token is invalid > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: A valid registry token is required to perform the action. The
› registry token used does not exist or has been revoked. [106]
Expand Down Expand Up @@ -703,7 +703,7 @@ http://__URL__
exports[`STITCHING > publish validates the service name > onlyNumbers 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
Expand All @@ -720,7 +720,7 @@ stdout--------------------------------------------:
exports[`STITCHING > publish validates the service name > specialCharacters 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: Schema publish failed. [300]
› > See https://__URL__ for
Expand All @@ -745,7 +745,7 @@ stdout--------------------------------------------:
exports[`STITCHING > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
3
stderr--------------------------------------------:
› Error: The SDL is not valid at line 1, column 1:
› Syntax Error: Unexpected Name "iliketurtles". [301]
Expand Down Expand Up @@ -823,7 +823,7 @@ stdout--------------------------------------------:
exports[`STITCHING > schema:publish should see Invalid Token error when token is invalid > schemaPublish 1`] = `
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: A valid registry token is required to perform the action. The
› registry token used does not exist or has been revoked. [106]
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/cli/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ test.concurrent(
).rejects.toMatchInlineSnapshot(`
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
1
stderr--------------------------------------------:
› Error: No access (reason: "Missing permission for performing
› 'schemaVersion:publish' on resource") (Request ID: __REQUEST_ID__) [115]
Expand Down Expand Up @@ -785,7 +785,7 @@ test('schema:check without `--target` flag fails for organization access token',
).rejects.toMatchInlineSnapshot(`
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
3
stderr--------------------------------------------:
› Error: Missing 1 required argument:
› TARGET The target on which the action is performed. This can either be a
Expand Down Expand Up @@ -857,7 +857,7 @@ test('schema:publish without `--target` flag fails for organization access token
).rejects.toMatchInlineSnapshot(`
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
exitCode------------------------------------------:
2
3
stderr--------------------------------------------:
› Error: Missing 1 required argument:
› TARGET The target on which the action is performed. This can either be a
Expand Down
4 changes: 3 additions & 1 deletion packages/libraries/cli/src/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class HiveCLIError extends CLIError {
) {
const tip = `> See https://the-guild.dev/graphql/hive/docs/api-reference/cli#errors for a complete list of error codes and recommended fixes.
To disable this message set HIVE_NO_ERROR_TIP=1`;
super(`${message} [${code}]${env.HIVE_NO_ERROR_TIP === '1' ? '' : `\n${tip}`}`);
super(`${message} [${code}]${env.HIVE_NO_ERROR_TIP === '1' ? '' : `\n${tip}`}`, {
exit: exitCode,
});
}
}

Expand Down
Loading