-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Port parts of Structured Errors to TS + Add two more errors #20597
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
38e3b6a
Convert first error files over to TS + add Joi typings
LekoArts dffa76f
Type more stuff
LekoArts 37546e1
Error 85926
LekoArts 5655304
Rename tests
LekoArts 2bcf5a8
Error 85927
LekoArts dd609b1
Fix ts type errors for test
LekoArts cd1437f
WIP: Warn on using .gif in image sharp
LekoArts 6844972
Some more typing stuff
LekoArts c2a11bf
Remove WIP .gif stuff
LekoArts e1de81a
Convert another test to TS
LekoArts 9a2a3f6
Update snapshot, add describe block
LekoArts 7cde48f
Update snapshot
LekoArts 33e78ee
Merge branch 'master' into improve-errors-2
ascorbic 4f7b7a3
Fix missing return type
ascorbic bb22972
Fix type error and explicitly type error map
ascorbic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
...tured-errors/__tests__/construct-error.js → ...tured-errors/__tests__/construct-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../structured-errors/__tests__/error-map.js → .../structured-errors/__tests__/error-map.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ructured-errors/__tests__/error-schema.js → ...ructured-errors/__tests__/error-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
packages/gatsby-cli/src/structured-errors/construct-error.js
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
packages/gatsby-cli/src/structured-errors/construct-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Joi from "@hapi/joi" | ||
import stackTrace from "stack-trace" | ||
import errorSchema from "./error-schema" | ||
import { errorMap, defaultError, IErrorMapEntry, ErrorId } from "./error-map" | ||
import { sanitizeStructuredStackTrace } from "../reporter/errors" | ||
|
||
interface IConstructError { | ||
details: { | ||
id?: ErrorId | ||
context?: Record<string, string> | ||
error?: string | ||
[key: string]: unknown | ||
} | ||
} | ||
|
||
interface ILocationPosition { | ||
line: number | ||
column: number | ||
} | ||
|
||
interface IStructuredError { | ||
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. This schema is more or less copied from the |
||
code?: string | ||
text: string | ||
stack: { | ||
fileName: string | ||
functionName?: string | ||
lineNumber?: number | ||
columnNumber?: number | ||
}[] | ||
filePath?: string | ||
location?: { | ||
start: ILocationPosition | ||
end?: ILocationPosition | ||
} | ||
error?: unknown | ||
group?: string | ||
level: IErrorMapEntry["level"] | ||
type?: IErrorMapEntry["type"] | ||
docsUrl?: string | ||
} | ||
|
||
// Merge partial error details with information from the errorMap | ||
// Validate the constructed object against an error schema | ||
const constructError = ({ | ||
details: { id, ...otherDetails }, | ||
}: IConstructError): IStructuredError => { | ||
const result: IErrorMapEntry = (id && errorMap[id]) || defaultError | ||
|
||
// merge | ||
const structuredError: IStructuredError = { | ||
context: {}, | ||
...otherDetails, | ||
...result, | ||
text: result.text(otherDetails.context), | ||
stack: otherDetails.error | ||
? sanitizeStructuredStackTrace(stackTrace.parse(otherDetails.error)) | ||
: null, | ||
docsUrl: result.docsUrl || `https://gatsby.dev/issue-how-to`, | ||
} | ||
|
||
if (id) { | ||
structuredError.code = id | ||
} | ||
|
||
// validate | ||
const { error } = Joi.validate(structuredError, errorSchema) | ||
if (error !== null) { | ||
console.log(`Failed to validate error`, error) | ||
process.exit(1) | ||
} | ||
|
||
return structuredError | ||
} | ||
|
||
export default constructError |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
lol what a goofy syntax