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): Pass failOn to all pipelines #37177

Merged
merged 4 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/README.md
Expand Up @@ -347,7 +347,7 @@ GATSBY_JPEG_ENCODER=MOZJPEG

### Allow build to continue on image processing error

By default, the build will fail when it encounters an error while processing an image. You can change this so that it continues the build process by setting the plugin option `failOnError` to `false`. Sharp will still throw an error and display it in the console as a GraphQL error, but it will not exit the process. It is important to note that any images that would have otherwise failed will not be accessible via `childImageSharp` until the underlying issue with the image is addressed.
By default, the build will fail when it encounters an error while processing an image. You can change this so that it continues the build process by setting the plugin option `failOn` to `none`. Sharp will still throw an error and display it in the console as a GraphQL error, but it will not exit the process. It is important to note that any images that would have otherwise failed will not be accessible via `childImageSharp` until the underlying issue with the image is addressed.

### EXIF and ICC metadata

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/src/gatsby-node.js
Expand Up @@ -208,7 +208,7 @@ exports.pluginOptionsSchema = ({ Joi }) =>
),
stripMetadata: Joi.boolean().default(true),
defaultQuality: Joi.number().default(50),
// TODO(v5): Remove deprecated failOnError option
// TODO(v6): Remove deprecated failOnError option
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we missed this 🙈

failOnError: Joi.boolean().default(true),
failOn: Joi.any()
.valid(`none`, `truncated`, `error`, `warning`)
Expand Down
11 changes: 0 additions & 11 deletions packages/gatsby-plugin-sharp/src/image-data.ts
Expand Up @@ -396,17 +396,6 @@ export async function generateImageData({
imageProps.placeholder = {
fallback,
}
} else if (placeholder === `tracedSVG`) {
const fallback: string = await traceSVG({
file,
args: tracedSVGOptions,
fileArgs: args,
cache,
reporter,
})
imageProps.placeholder = {
fallback,
}
} else if (metadata?.dominantColor) {
imageProps.backgroundColor = metadata.dominantColor
}
Expand Down
8 changes: 5 additions & 3 deletions packages/gatsby-plugin-sharp/src/index.js
Expand Up @@ -395,9 +395,10 @@ async function traceSVG(args) {
}

async function stats({ file, reporter }) {
const pluginOptions = getPluginOptions()
let imgStats
try {
const pipeline = sharp()
const pipeline = sharp({ failOn: pluginOptions.failOn })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, passing failOn down to sharp makes sense.

How about also passing the pluginOptions down to reportErrors so we can control the behavior of reportError (not to exit the whole process)?

fs.createReadStream(file.absolutePath).pipe(pipeline)

imgStats = await pipeline.stats()
Expand All @@ -417,11 +418,12 @@ async function stats({ file, reporter }) {

let didShowTraceSVGRemovalWarningFluid = false
async function fluid({ file, args = {}, reporter, cache }) {
const options = healOptions(getPluginOptions(), args, file.extension)
const pluginOptions = getPluginOptions()
const options = healOptions(pluginOptions, args, file.extension)

let metadata
try {
const pipeline = sharp()
const pipeline = sharp({ failOn: pluginOptions.failOn })
fs.createReadStream(file.absolutePath).pipe(pipeline)

metadata = await pipeline.metadata()
Expand Down