-
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
feat(gatsby): enable richer error handling for unknown APIs #16105
Changes from 6 commits
025874f
c6864a7
f1ea99e
b7a1930
7861d1f
74b4564
a2dabd0
b4665f9
4c8a7d1
3cbd0f0
bf55206
d4aa82d
59bf7a3
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const { stripIndent } = require(`common-tags`) | ||
|
||
const errorMap = { | ||
"": { | ||
text: context => { | ||
|
@@ -160,6 +162,34 @@ const errorMap = { | |
}`, | ||
level: `ERROR`, | ||
}, | ||
// invalid or deprecated APIs | ||
"11329": { | ||
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. Is there a pattern to these errors? Were the error codes chosen for a reason, or am I correct in presuming it's effectively an incrementing id that just makes things easier to Google? Also next-level would be to generate docs pages based on these structured errors, and then provide even richer detail e.g.
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. There is no special meaning to codes. Actually if codes have less patterns the better ;) We want them to be easily google-able (for example to find related issues if linked docs are not enough). So best avoid codes like 11111, 12345 that have higher chance of returning unrelated search results. One thing that is not really specified, but I think could make sense here, is to not increment by 1 when adding new structured error (if new error is related to different thing than last one). 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. We should just print a prefix maybe then? GTSB-12345 is pretty unique! 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. @pieh circling back to this. Few questions:
What are you proposing here exactly?
I'm happy to add it there (what you may be saying?) but those are config errors? This could be a gatsby-node.js error, but it wouldn't be a config error necessarily. |
||
text: context => | ||
[ | ||
stripIndent(` | ||
Your plugins must export known APIs from their gatsby-${ | ||
context.exportType | ||
}.js. | ||
|
||
See https://www.gatsbyjs.org/docs/${ | ||
context.exportType | ||
}-apis/ for the list of Gatsby ${context.exportType} APIs. | ||
`), | ||
] | ||
.concat([``].concat(context.errors)) | ||
.concat( | ||
context.fixes.length > 0 | ||
? [ | ||
``, | ||
`Some of the following may help fix the error(s):`, | ||
``, | ||
...context.fixes.map(fix => `- ${fix}`), | ||
] | ||
: [] | ||
) | ||
.join(`\n`), | ||
level: `ERROR`, | ||
}, | ||
} | ||
|
||
module.exports = { errorMap, defaultError: errorMap[``] } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,8 @@ decls | |
dist | ||
|
||
# built files | ||
cache-dir/commonjs/ | ||
apis.json | ||
cache-dir/commonjs/ | ||
|
||
# cached files | ||
/latest-apis.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
try { | ||
const getLatestAPIs = require('../dist/utils/get-latest-apis') | ||
getLatestAPIs() | ||
} catch (e) { | ||
// we're probably just bootstrapping and not published yet! | ||
} |
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'll remove this -- I was testing with a structured "error" of warning.
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.
We need
theme-ui
theme for CLI!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! Design tokens and theme-ui for our CLI, I like it!