Skip to content

Commit 5ee3a2e

Browse files
authored
Specify oclif exitcode in cli errors (#6768)
1 parent e818c95 commit 5ee3a2e

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

.changeset/weak-crabs-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/cli': patch
3+
---
4+
5+
Correct error exit codes

integration-tests/tests/api/target/usage.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test.concurrent(
9292
},
9393
]);
9494
expect(collectResult.status).toEqual(200);
95-
await waitFor(8000);
95+
await waitFor(10_000);
9696

9797
// should be breaking because the field is used now
9898
const usedCheckResult = await readToken
@@ -123,6 +123,9 @@ test.concurrent(
123123
expect(op.name).toMatch('ping');
124124
expect(op.percentage).toBeGreaterThan(99);
125125
},
126+
{
127+
timeout: 15_000,
128+
},
126129
);
127130

128131
test.concurrent(

integration-tests/tests/cli/__snapshots__/schema.spec.ts.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ http://__URL__
156156
exports[`FEDERATION > publish validates the service name > onlyNumbers 1`] = `
157157
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
158158
exitCode------------------------------------------:
159-
2
159+
1
160160
stderr--------------------------------------------:
161161
› Error: Schema publish failed. [300]
162162
› > See https://__URL__ for
@@ -173,7 +173,7 @@ stdout--------------------------------------------:
173173
exports[`FEDERATION > publish validates the service name > specialCharacters 1`] = `
174174
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
175175
exitCode------------------------------------------:
176-
2
176+
1
177177
stderr--------------------------------------------:
178178
› Error: Schema publish failed. [300]
179179
› > See https://__URL__ for
@@ -198,7 +198,7 @@ stdout--------------------------------------------:
198198
exports[`FEDERATION > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
199199
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
200200
exitCode------------------------------------------:
201-
2
201+
3
202202
stderr--------------------------------------------:
203203
› Error: The SDL is not valid at line 1, column 1:
204204
› Syntax Error: Unexpected Name "iliketurtles". [301]
@@ -274,7 +274,7 @@ stdout--------------------------------------------:
274274
exports[`FEDERATION > schema:publish should see Invalid Token error when token is invalid > schemaPublish 1`] = `
275275
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
276276
exitCode------------------------------------------:
277-
2
277+
1
278278
stderr--------------------------------------------:
279279
› Error: A valid registry token is required to perform the action. The
280280
› registry token used does not exist or has been revoked. [106]
@@ -461,7 +461,7 @@ stdout--------------------------------------------:
461461
exports[`SINGLE > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
462462
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
463463
exitCode------------------------------------------:
464-
2
464+
3
465465
stderr--------------------------------------------:
466466
› Error: The SDL is not valid at line 1, column 1:
467467
› Syntax Error: Unexpected Name "iliketurtles". [301]
@@ -542,7 +542,7 @@ stdout--------------------------------------------:
542542
exports[`SINGLE > schema:publish should see Invalid Token error when token is invalid > schemaPublish 1`] = `
543543
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
544544
exitCode------------------------------------------:
545-
2
545+
1
546546
stderr--------------------------------------------:
547547
› Error: A valid registry token is required to perform the action. The
548548
› registry token used does not exist or has been revoked. [106]
@@ -703,7 +703,7 @@ http://__URL__
703703
exports[`STITCHING > publish validates the service name > onlyNumbers 1`] = `
704704
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
705705
exitCode------------------------------------------:
706-
2
706+
1
707707
stderr--------------------------------------------:
708708
› Error: Schema publish failed. [300]
709709
› > See https://__URL__ for
@@ -720,7 +720,7 @@ stdout--------------------------------------------:
720720
exports[`STITCHING > publish validates the service name > specialCharacters 1`] = `
721721
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
722722
exitCode------------------------------------------:
723-
2
723+
1
724724
stderr--------------------------------------------:
725725
› Error: Schema publish failed. [300]
726726
› > See https://__URL__ for
@@ -745,7 +745,7 @@ stdout--------------------------------------------:
745745
exports[`STITCHING > publishing invalid schema SDL provides meaningful feedback for the user. > schemaPublish 1`] = `
746746
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
747747
exitCode------------------------------------------:
748-
2
748+
3
749749
stderr--------------------------------------------:
750750
› Error: The SDL is not valid at line 1, column 1:
751751
› Syntax Error: Unexpected Name "iliketurtles". [301]
@@ -823,7 +823,7 @@ stdout--------------------------------------------:
823823
exports[`STITCHING > schema:publish should see Invalid Token error when token is invalid > schemaPublish 1`] = `
824824
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
825825
exitCode------------------------------------------:
826-
2
826+
1
827827
stderr--------------------------------------------:
828828
› Error: A valid registry token is required to perform the action. The
829829
› registry token used does not exist or has been revoked. [106]

integration-tests/tests/cli/schema.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ test.concurrent(
704704
).rejects.toMatchInlineSnapshot(`
705705
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
706706
exitCode------------------------------------------:
707-
2
707+
1
708708
stderr--------------------------------------------:
709709
› Error: No access (reason: "Missing permission for performing
710710
› 'schemaVersion:publish' on resource") (Request ID: __REQUEST_ID__) [115]
@@ -785,7 +785,7 @@ test('schema:check without `--target` flag fails for organization access token',
785785
).rejects.toMatchInlineSnapshot(`
786786
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
787787
exitCode------------------------------------------:
788-
2
788+
3
789789
stderr--------------------------------------------:
790790
› Error: Missing 1 required argument:
791791
› TARGET The target on which the action is performed. This can either be a
@@ -857,7 +857,7 @@ test('schema:publish without `--target` flag fails for organization access token
857857
).rejects.toMatchInlineSnapshot(`
858858
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
859859
exitCode------------------------------------------:
860-
2
860+
3
861861
stderr--------------------------------------------:
862862
› Error: Missing 1 required argument:
863863
› TARGET The target on which the action is performed. This can either be a

packages/libraries/cli/src/helpers/errors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export class HiveCLIError extends CLIError {
3030
) {
3131
const tip = `> See https://the-guild.dev/graphql/hive/docs/api-reference/cli#errors for a complete list of error codes and recommended fixes.
3232
To disable this message set HIVE_NO_ERROR_TIP=1`;
33-
super(`${message} [${code}]${env.HIVE_NO_ERROR_TIP === '1' ? '' : `\n${tip}`}`);
33+
super(`${message} [${code}]${env.HIVE_NO_ERROR_TIP === '1' ? '' : `\n${tip}`}`, {
34+
exit: exitCode,
35+
});
3436
}
3537
}
3638

0 commit comments

Comments
 (0)