Skip to content

fix(cli): use correct error codes and add more context #6820

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 2 commits into from
Jun 2, 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
4 changes: 2 additions & 2 deletions packages/libraries/cli/src/commands/schema/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as GraphQLSchema from '../../gql/graphql';
import { graphqlEndpoint } from '../../helpers/config';
import {
APIError,
GithubCommitRequiredError,
CommitRequiredError,
GithubRepositoryRequiredError,
InvalidTargetError,
MissingEndpointError,
Expand Down Expand Up @@ -227,7 +227,7 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {

if (usesGitHubApp) {
if (!commit) {
throw new GithubCommitRequiredError();
throw new CommitRequiredError();
Copy link
Collaborator

Choose a reason for hiding this comment

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

These could probably be generic bad input errors instead of special cases

}
if (!git.repository) {
throw new GithubRepositoryRequiredError();
Expand Down
8 changes: 4 additions & 4 deletions packages/libraries/cli/src/commands/schema/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import * as GraphQLSchema from '../../gql/graphql';
import { graphqlEndpoint } from '../../helpers/config';
import {
APIError,
GithubAuthorRequiredError,
GithubCommitRequiredError,
AuthorRequiredError,
CommitRequiredError,
InvalidSDLError,
InvalidTargetError,
MissingEndpointError,
Expand Down Expand Up @@ -239,11 +239,11 @@ export default class SchemaPublish extends Command<typeof SchemaPublish> {
}

if (!author) {
throw new GithubAuthorRequiredError();
throw new AuthorRequiredError();
}

if (!commit) {
throw new GithubCommitRequiredError();
throw new CommitRequiredError();
}

if (usesGitHubApp) {
Expand Down
8 changes: 4 additions & 4 deletions packages/libraries/cli/src/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ export class SchemaFileEmptyError extends HiveCLIError {
}
}

export class GithubCommitRequiredError extends HiveCLIError {
export class CommitRequiredError extends HiveCLIError {
constructor() {
super(
ExitCode.BAD_INIT,
errorCode(ErrorCategory.GENERIC, 10),
`Couldn't resolve commit sha required for GitHub Application.`,
`Couldn't resolve required commit sha. Provide a non-empty author via the '--commit' parameter or execute the command within a git repository.`,
);
}
}
Expand All @@ -188,12 +188,12 @@ export class GithubRepositoryRequiredError extends HiveCLIError {
}
}

export class GithubAuthorRequiredError extends HiveCLIError {
export class AuthorRequiredError extends HiveCLIError {
constructor() {
super(
ExitCode.BAD_INIT,
errorCode(ErrorCategory.GENERIC, 12),
`Couldn't resolve commit author required for GitHub Application.`,
`Couldn't resolve required commit author. Provide a non-empty author via the '--author' parameter or execute the command within a git repository.`,
);
}
}
Expand Down
16 changes: 9 additions & 7 deletions packages/web/docs/src/components/cli-errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ export async function getErrorDescriptions(): Promise<CLIError[]> {
},
{
instance: {
name: 'GithubCommitRequiredError',
name: 'CommitRequiredError',
code: '110',
message: "Couldn't resolve commit sha required for GitHub Application.",
message:
"Couldn't resolve required commit sha. Provide a non-empty author via the '--commit' parameter or execute the command within a git repository.",
},
example: 'hive schema:check FILE --github',
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.',
fix: "Make sure the command is called within a valid git repository directory or the '--commit' parameter is provided with a non-empty value.",
},
{
instance: {
Expand All @@ -180,16 +181,17 @@ export async function getErrorDescriptions(): Promise<CLIError[]> {
message: "Couldn't resolve git repository required for GitHub Application.",
},
example: 'hive schema:check FILE --github',
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.',
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.',
},
{
instance: {
name: 'GithubAuthorRequiredError',
name: 'AuthorRequiredError',
code: '112',
message: "Couldn't resolve commit author required for GitHub Application.",
message:
"Couldn't resolve required commit author. Provide a non-empty author via the '--author' parameter or execute the command within a git repository.",
},
example: 'hive schema:check FILE --github',
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.',
fix: "Make sure the command is called within a valid git repository directory or the '--author' parameter is provided with a non-empty value.",
},
{
instance: {
Expand Down
Loading
Loading