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

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Dec 5, 2022

Description

#37165 tried to fix an error that really should be fixed by correctly passing failOn to all our sharp pipelines.

Related Issues

#37151

[ch59059]

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 5, 2022
@LekoArts LekoArts added topic: media Related to gatsby-plugin-image, or general image/media processing topics and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Dec 5, 2022
@LekoArts LekoArts changed the title fix(gatsby-plugin-sharp): Pass failOn to all pipelines fix(gatsby-plugin-sharp): Pass failOn to all pipelines Dec 5, 2022
@@ -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 🙈

@Jeff-Tian
Copy link

Hey, you closed my PR #37165 and copied most code changes into this PR, but you lost the test case, which is terrible.

@LekoArts
Copy link
Contributor Author

LekoArts commented Dec 6, 2022

@Jeff-Tian can you please generate a smaller file? I don't want to add 4MB to this repository just for this one test case. Ideal would be below 500KB

@Jeff-Tian
Copy link

Yes, there are rooms to improve for #37165, but you can comment and I can change it there, instead of closing it directly.

@LekoArts
Copy link
Contributor Author

LekoArts commented Dec 6, 2022

If it's about co-authorship for you I'm happy to add you to the commit, I just closed it because I wanted to do you a favor and fix it in a timely manner as your PR was incorrect. Going back and forth in a PR takes way more time than talking about it in advance (e.g. in a discussion) and then have a clear plan for a PR from the get go. If you give me a smaller test image I'll add it as a test case.

Sorry if that made you feel unappreciated, that wasn't my intention.

@Jeff-Tian
Copy link

@LekoArts Thanks, feel much better now. However, I can only trigger the meta data error with the 4MB picture. If I compressed it then the meta data error won't occur.

@LekoArts
Copy link
Contributor Author

LekoArts commented Dec 7, 2022

After talking to the author of sharp in lovell/sharp#3480 I also updated the wording on the failOn settting and the correct expectations of it. The test image you had in your PR will still fail because the image headers are corrupted. We still want to fail on this. I don't have a test file at hand that has correct headers but wrong pixel values, so we'll just assume that this is covered by sharp itself as a test case (which it is).

@Jeff-Tian
Copy link

Hi @LekoArts, I managed to create a very small png file that can trigger the metadata error. See #37203.

You mentioned that my PR #37165 was not correctly fixed the issue, but in contrast, this PR can NOT fix the issue unless includes the #37203 in.

Although the failOn option passes to sharp, it doesn't pass to reportError.

We might think that setting failOn to none will make sharp not throwing. However, by adding a test case, I found it still throws.

So I still insist passing the pluginOptions down to reportError. Does it make sense to you?

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)?

@LekoArts
Copy link
Contributor Author

LekoArts commented Dec 7, 2022

If sharp thinks an image is invalid and an error should be thrown, gatsby-plugin-sharp should behave the same. Otherwise we have different behaviors between the two and it won't be clear in the future why an error is thrown or not. That's why I don't want to add the change to the reportError you added. So yes, it won't fix your issue, you'll need to use non-corrupt images.

Allowing the option you made in the other PR is a footgun for people and would allow them to ship missing images to the production site which we don't want.

@Jeff-Tian
Copy link

Jeff-Tian commented Dec 7, 2022

It's not the case. See #37165's test image, it's NOT a corrupt image. It's a normal image and there are many similar images widely used.

There are cases that a gatsby site contains many images, and only a few normal images happen to trigger the sharp throw an exception. In this scenario, we the site builders should have a way to control the whole building process.

And the pluginOptions is the perfect way to control, isn't it?

If you want the whole process to exit when sharp throws you can still set failOn to other values.

@LekoArts
Copy link
Contributor Author

LekoArts commented Dec 7, 2022

Please open an issue on https://github.com/lovell/sharp/issues about that specific image then, sharp thinks it's corrupt so we'll handle it that way.

@LekoArts LekoArts merged commit 908ab89 into master Dec 8, 2022
@LekoArts LekoArts deleted the sharp-more-fail-on branch December 8, 2022 07:12
@Jeff-Tian
Copy link

If it's about co-authorship for you I'm happy to add you to the commit, I just closed it because I wanted to do you a favor and fix it in a timely manner as your PR was incorrect. Going back and forth in a PR takes way more time than talking about it in advance (e.g. in a discussion) and then have a clear plan for a PR from the get go. If you give me a smaller test image I'll add it as a test case.

Sorry if that made you feel unappreciated, that wasn't my intention.

Could you please add me to the commit? @LekoArts

LekoArts added a commit that referenced this pull request Dec 8, 2022
Co-authored By: Jeff Tian <jeff.tian@outlook.com>
@LekoArts
Copy link
Contributor Author

LekoArts commented Dec 8, 2022

@Jeff-Tian Done 👍

@Jeff-Tian
Copy link

Please open an issue on https://github.com/lovell/sharp/issues about that specific image then, sharp thinks it's corrupt so we'll handle it that way.

Hi @LekoArts, sorry for the late response to this issue.

With the help of the author of sharp (lovell/sharp#3509), it turns out that the root cause of the building process halt is that some images with png extension actually are BMP images.

And that makes sharp(...).metadata failed as seems sharp doesn't support BMP image formats natively.

I found ways to detect these images (lovell/sharp#806 (comment)).

I am still trying to make my gatsby site building process continue even with those fake png files. So I am thinking to insert some code to detect the images and if BMP is found, then using bmp-js to decode them.

Is it a correct way to insert these kind of logic to gatsby-plugin-sharp? If not, what is the best way to handle BMP images during gatsby building?

Thanks in advance!

@jcpmcc5
Copy link

jcpmcc5 commented Sep 26, 2023

Please open an issue on https://github.com/lovell/sharp/issues about that specific image then, sharp thinks it's corrupt so we'll handle it that way.

Hi @LekoArts, sorry for the late response to this issue.

With the help of the author of sharp (lovell/sharp#3509), it turns out that the root cause of the building process halt is that some images with png extension actually are BMP images.

And that makes sharp(...).metadata failed as seems sharp doesn't support BMP image formats natively.

I found ways to detect these images (lovell/sharp#806 (comment)).

I am still trying to make my gatsby site building process continue even with those fake png files. So I am thinking to insert some code to detect the images and if BMP is found, then using bmp-js to decode them.

Is it a correct way to insert these kind of logic to gatsby-plugin-sharp? If not, what is the best way to handle BMP images during gatsby building?

Thanks in advance!

Any updates on handling bmp images during gatsby building? Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: media Related to gatsby-plugin-image, or general image/media processing topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants