Skip to content

Commit 5fa121f

Browse files
authored
fix(cli): use correct error codes and add more context (#6820)
1 parent 7e753a5 commit 5fa121f

File tree

5 files changed

+198
-121
lines changed

5 files changed

+198
-121
lines changed

packages/libraries/cli/src/commands/schema/check.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as GraphQLSchema from '../../gql/graphql';
66
import { graphqlEndpoint } from '../../helpers/config';
77
import {
88
APIError,
9-
GithubCommitRequiredError,
9+
CommitRequiredError,
1010
GithubRepositoryRequiredError,
1111
InvalidTargetError,
1212
MissingEndpointError,
@@ -227,7 +227,7 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {
227227

228228
if (usesGitHubApp) {
229229
if (!commit) {
230-
throw new GithubCommitRequiredError();
230+
throw new CommitRequiredError();
231231
}
232232
if (!git.repository) {
233233
throw new GithubRepositoryRequiredError();

packages/libraries/cli/src/commands/schema/publish.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import * as GraphQLSchema from '../../gql/graphql';
77
import { graphqlEndpoint } from '../../helpers/config';
88
import {
99
APIError,
10-
GithubAuthorRequiredError,
11-
GithubCommitRequiredError,
10+
AuthorRequiredError,
11+
CommitRequiredError,
1212
InvalidSDLError,
1313
InvalidTargetError,
1414
MissingEndpointError,
@@ -239,11 +239,11 @@ export default class SchemaPublish extends Command<typeof SchemaPublish> {
239239
}
240240

241241
if (!author) {
242-
throw new GithubAuthorRequiredError();
242+
throw new AuthorRequiredError();
243243
}
244244

245245
if (!commit) {
246-
throw new GithubCommitRequiredError();
246+
throw new CommitRequiredError();
247247
}
248248

249249
if (usesGitHubApp) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ export class SchemaFileEmptyError extends HiveCLIError {
168168
}
169169
}
170170

171-
export class GithubCommitRequiredError extends HiveCLIError {
171+
export class CommitRequiredError extends HiveCLIError {
172172
constructor() {
173173
super(
174174
ExitCode.BAD_INIT,
175175
errorCode(ErrorCategory.GENERIC, 10),
176-
`Couldn't resolve commit sha required for GitHub Application.`,
176+
`Couldn't resolve required commit sha. Provide a non-empty author via the '--commit' parameter or execute the command within a git repository.`,
177177
);
178178
}
179179
}
@@ -188,12 +188,12 @@ export class GithubRepositoryRequiredError extends HiveCLIError {
188188
}
189189
}
190190

191-
export class GithubAuthorRequiredError extends HiveCLIError {
191+
export class AuthorRequiredError extends HiveCLIError {
192192
constructor() {
193193
super(
194194
ExitCode.BAD_INIT,
195195
errorCode(ErrorCategory.GENERIC, 12),
196-
`Couldn't resolve commit author required for GitHub Application.`,
196+
`Couldn't resolve required commit author. Provide a non-empty author via the '--author' parameter or execute the command within a git repository.`,
197197
);
198198
}
199199
}

packages/web/docs/src/components/cli-errors.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,13 @@ export async function getErrorDescriptions(): Promise<CLIError[]> {
166166
},
167167
{
168168
instance: {
169-
name: 'GithubCommitRequiredError',
169+
name: 'CommitRequiredError',
170170
code: '110',
171-
message: "Couldn't resolve commit sha required for GitHub Application.",
171+
message:
172+
"Couldn't resolve required commit sha. Provide a non-empty author via the '--commit' parameter or execute the command within a git repository.",
172173
},
173174
example: 'hive schema:check FILE --github',
174-
fix: 'Make sure the command is called within a valid git project. To use the Github integration, there must be at a commit in the history to reference. The commit sha is set as the schema version in the registry and is used for change approvals and other features. See https://the-guild.dev/graphql/hive/docs/management/organizations#github for more details about this integration.',
175+
fix: "Make sure the command is called within a valid git repository directory or the '--commit' parameter is provided with a non-empty value.",
175176
},
176177
{
177178
instance: {
@@ -180,16 +181,17 @@ export async function getErrorDescriptions(): Promise<CLIError[]> {
180181
message: "Couldn't resolve git repository required for GitHub Application.",
181182
},
182183
example: 'hive schema:check FILE --github',
183-
fix: 'Make sure the command is called within a valid git project. See https://the-guild.dev/graphql/hive/docs/management/organizations#github for more details about this integration.',
184+
fix: 'Make sure the command is called within a valid git repository directory. See https://the-guild.dev/graphql/hive/docs/management/organizations#github for more details about this integration.',
184185
},
185186
{
186187
instance: {
187-
name: 'GithubAuthorRequiredError',
188+
name: 'AuthorRequiredError',
188189
code: '112',
189-
message: "Couldn't resolve commit author required for GitHub Application.",
190+
message:
191+
"Couldn't resolve required commit author. Provide a non-empty author via the '--author' parameter or execute the command within a git repository.",
190192
},
191193
example: 'hive schema:check FILE --github',
192-
fix: 'Make sure the command is called within a valid git project. See https://the-guild.dev/graphql/hive/docs/management/organizations#github for more details about this integration.',
194+
fix: "Make sure the command is called within a valid git repository directory or the '--author' parameter is provided with a non-empty value.",
193195
},
194196
{
195197
instance: {

0 commit comments

Comments
 (0)