Skip to content
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

fix(gatsby,gatsby-cli): Correct behavior for reporter.error with pluginName #30331

Merged
merged 6 commits into from
Mar 23, 2021

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Mar 18, 2021

Description

Passing the Error object to e.g. reporter.panic (or all reporter.error invocations really) wasn't working as intended. It always showed the "There was an error" generic error.

The culprit is that

const addPluginNameToErrorMeta = (errorMeta, pluginName) =>
typeof errorMeta === `string`
? {
context: {
sourceMessage: errorMeta,
},
pluginName,
}
: {
...errorMeta,
pluginName,
}
was added but doesn't handle all the cases that
error = (
errorMeta: ErrorMeta | Array<ErrorMeta>,
error?: Error | Array<Error>
): IStructuredError | Array<IStructuredError> => {
does handle.

So instead of repeating the code and possibly diverge in the future, pluginName is now passed as an optional third param.

I've also updated the default catch-all error to be more helpful and added tests to show that correct behavior.

Documentation

The API docs for now will still promote reporter.panic('text', new Error('text'))

Related Issues

[ch27056]

@LekoArts LekoArts added topic: cli Related to the Gatsby CLI topic: reporter labels Mar 18, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 18, 2021
@LekoArts LekoArts changed the title fix(gatsby,gatsby-cli): fix(gatsby,gatsby-cli): Correct behavior for reporter.error with pluginName Mar 18, 2021
@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 18, 2021
@LekoArts LekoArts marked this pull request as ready for review March 22, 2021 09:24
@LekoArts LekoArts merged commit eb1e2d8 into master Mar 23, 2021
@LekoArts LekoArts deleted the update-reporter-jsdoc branch March 23, 2021 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: cli Related to the Gatsby CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants