-
Notifications
You must be signed in to change notification settings - Fork 128
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
Report GraphQL system errors as expected #4811
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ export async function handler(error: unknown): Promise<unknown> { | |
} else if (typeof error === 'string') { | ||
fatal = new BugError(error) | ||
} else if (error instanceof Error) { | ||
fatal = new BugError(error.message) | ||
fatal = isGraphQLError(error) ? new AbortError(error.message) : new BugError(error.message) | ||
fatal.stack = error.stack | ||
} else { | ||
// errors can come in all shapes and sizes... | ||
|
@@ -188,6 +188,9 @@ function isFatal(error: unknown): error is FatalError { | |
*/ | ||
export function shouldReportErrorAsUnexpected(error: unknown): boolean { | ||
if (!isFatal(error)) { | ||
if (isInternalGraphQLError(error)) { | ||
return false | ||
} | ||
// this means its not one of the CLI wrapped errors | ||
if (error instanceof Error) { | ||
const message = error.message | ||
|
@@ -234,3 +237,31 @@ function errorMessageImpliesEnvironmentIssue(message: string): boolean { | |
const anyMatches = environmentIssueMessages.some((issueMessage) => message.includes(issueMessage)) | ||
return anyMatches | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
function isInternalGraphQLError(error: any): boolean { | ||
if (!isGraphQLError(error)) { | ||
return false | ||
} | ||
|
||
const extensions = error?.errors?.[0]?.extensions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below, we are looking at only the first error, so this still needs work. The logic shoujld be that the error is internal if any of the errors in the array are internal. |
||
|
||
// App Management errors have a category that can be used to determine if the error is internal | ||
const category: string | undefined = extensions?.app_errors?.errors?.[0]?.category | ||
if (category) { | ||
return category === 'internal' | ||
} | ||
|
||
// Partners errors have a code that can be used to determine if the error is internal | ||
const code: string | undefined = extensions?.code | ||
if (code) { | ||
return parseInt(code, 10) >= 500 | ||
} | ||
|
||
return true | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function isGraphQLError(error: any): boolean { | ||
return error?.name === 'GraphQLClientError' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My attempts to use something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what you want here is a narrowing function. This is something that takes some input at runtime and if true, makes some implication about the provided value https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates So in this case, maybe roughly:
then elsewhere you can do
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not strictly necessary, but using the same type here allows us to retain information that is otherwise lost. This includes the specific error messages, the status code, and stack information.
Not sure of the original intent of "Client" here. Is it meant to convey a
4xx
class error, or an error received by the GraphQL client? If the former, then this new usage would require a rename, at least as currently written,.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its the latter but this is one of the older corners of things, I don't think there's any issue with making larger changes here if you see fit
I don't think we need to say
mappedError: Error
if its only going to ever be aGraphQLClientError
now.