Skip to content

Commit

Permalink
fix(gatsby): Handle double prefix case for `extendErrorIdWithPluginNa…
Browse files Browse the repository at this point in the history
…me` (#27547)

Co-authored-by: Peter van der Zee <209817+pvdz@users.noreply.github.com>
  • Loading branch information
LekoArts and pvdz authored Oct 20, 2020
1 parent 9e86f75 commit b4d8342
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
19 changes: 18 additions & 1 deletion integration-tests/structured-logging/__tests__/plugin-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ describe(`Plugin Errors`, () => {
action: expect.objectContaining({
type: `LOG`,
payload: expect.objectContaining({
level: "ERROR",
level: `ERROR`,
category: `SYSTEM`,
text: `Error text is MORE ERROR!`,
code: `structured-plugin-errors_12345`
})
})
})
])
)

expect(events).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `LOG`,
payload: expect.objectContaining({
level: `ERROR`,
category: `SYSTEM`,
text: `Error text is PANIC!`,
code: `structured-plugin-errors_1337`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ exports.onPreInit = ({ reporter }) => {
category: "SYSTEM",
docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new`,
},
"12345": {
text: context => `Error text is ${context && context.someProp}`,
level: "ERROR",
category: "SYSTEM",
docsUrl: `https://www.gatsbyjs.com/docs/cheat-sheet/`,
}
})

reporter.info("setErrorMap")

if (process.env.PANIC_IN_PLUGIN) {
reporter.error({ id: "structured-plugin-errors_12345", context: { someProp: `MORE ERROR!` } })
reporter.panic({ id: "1337", context: { someProp: `PANIC!` } })
}
}
7 changes: 4 additions & 3 deletions packages/gatsby/src/utils/api-runner-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ function getLocalReporter({ activity, reporter }) {
}

function extendErrorIdWithPluginName(pluginName, errorMeta) {
if (typeof errorMeta === `object`) {
const id = errorMeta && errorMeta[`id`]
if (id) {
const id = errorMeta?.id
if (id) {
const isPrefixed = id.includes(`${pluginName}_`)
if (!isPrefixed) {
return {
...errorMeta,
id: `${pluginName}_${id}`,
Expand Down

0 comments on commit b4d8342

Please sign in to comment.