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-plugin-sharp): regard failOn option inside reportError #37203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/gatsby-plugin-sharp/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ describe(`gatsby-plugin-sharp`, () => {
expect(actual.length).toEqual(expected.length)
expect(actions.createJobV2).toMatchSnapshot()
})

it(`reports metadata error without exiting`, async () => {
process.env.gatsby_executing_command = `build`
setPluginOptions({ failOn: `none` })

const result = await fluid({
file: getFileObject(path.join(__dirname, `images/metadata-error.png`)),
})

expect(result).toBeNull()
})
})

describe(`fixed`, () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ async function fluid({ file, args = {}, reporter, cache }) {
reportError(
`Failed to retrieve metadata from image ${file.absolutePath}`,
err,
reporter
reporter,
pluginOptions
)
return null
}
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-plugin-sharp/src/report-error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const reportError = (message, err, reporter) => {
const reportError = (message, err, reporter, pluginOptions) => {
if (reporter) {
reporter.error({
id: `gatsby-plugin-sharp-20000`,
Expand All @@ -9,6 +9,10 @@ const reportError = (message, err, reporter) => {
console.error(message, err)
}

if (pluginOptions.failOn === `none`) {
return
}

if (process.env.gatsby_executing_command === `build`) {
process.exit(1)
}
Expand Down