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

Add failOnError to suit #976

Merged
merged 8 commits into from
Oct 8, 2017
Merged

Add failOnError to suit #976

merged 8 commits into from
Oct 8, 2017

Conversation

mceachen
Copy link
Contributor

@mceachen mceachen commented Oct 4, 2017

  • Rebuilt diff on top of suit from Add failOnError #925
  • Addresses Support and document how to configure sharp to fail when loading corrupt images #793
  • I found that setting option->set("fail", FALSE) still set the flag (!!), so that flag is set conditionally in this branch.
  • Added tests for [JPG, PNG] x [without flag, with flag and callback, with flag and promise] combinations.
  • I gave up on "punched file" support, as the error messages depend on where the "holes" are, and libvips and libjpeg don't always agree on the validity of a JPEG stream.

@mceachen mceachen changed the title Add failOnError Add failOnError to suit Oct 4, 2017
@mceachen
Copy link
Contributor Author

mceachen commented Oct 5, 2017

The linux builds are passing now. Mac builds fail in the same fashion as your other suit branch builds, like https://travis-ci.org/lovell/sharp/builds/282365910, so I think this PR is ready to merge.

Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

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

This is looking great, thank you Matthew. I've left a couple of comments inline; nothing serious.

As you noticed, the OS X binaries for the pre-release libvips v8.6.0 are not yet ready so no need to worry about that platform at the moment.

The FALSE thing you mention is probably a case thing, which then made me realise that the existing C++ code should be using false everywhere instead. This is probably a hangover from when sharp was using the libvips' C API. I'll update that separately after this PR lands.

lib/input.js Outdated
@@ -26,6 +26,15 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
throw new Error('Unsupported input ' + typeof input);
}
if (is.object(inputOptions)) {
// Fail on error
inputDescriptor.failOnError = false;
Copy link
Owner

Choose a reason for hiding this comment

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

We could hoist the default to the beginning of this function, something like:

const inputDescriptor = { failOnError: false };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/common.cc Outdated
@@ -52,6 +52,9 @@ namespace sharp {
descriptor->buffer = node::Buffer::Data(buffer);
buffersToPersist.push_back(buffer);
}
if (HasAttr(input, "failOnError")) {
Copy link
Owner

Choose a reason for hiding this comment

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

Always having failOnError set in JS-land means we can remove a conditional here and always set it on the descriptor struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/common.cc Outdated
@@ -220,6 +223,9 @@ namespace sharp {
if (imageType != ImageType::UNKNOWN) {
try {
vips::VOption *option = VImage::option()->set("access", accessMethod);
if (descriptor->failOnError) {
Copy link
Owner

Choose a reason for hiding this comment

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

Ditto here, something like:

vips::VOption *option = VImage::option()
  ->set("access", accessMethod)
  ->set("fail", descriptor->failOnError);

Copy link
Owner

Choose a reason for hiding this comment

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

Should line 262 mirror the logic on line 223?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


it('returns errors to callback for truncated JPEG when failOnError is set', function (done) {
sharp(fixtures.inputJpgTruncated, { failOnError: true }).toBuffer(function (err, data, info) {
assert.ok(err.message.includes('VipsJpeg: Premature end of JPEG file'), err);
Copy link
Owner

Choose a reason for hiding this comment

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

I really like this. assert(err.message.includes( is highly fluent to read. 💯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

woot!

it('handles truncated JPEG by default', function (done) {
sharp(fixtures.inputJpgTruncated)
.resize(320, 240)
// .toFile(fixtures.expected('truncated.jpg'), done);
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like there are a couple of leftover comments in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

those comments were left in so Engineers of Tomorrow can easily re-create the truncated images (in case VIPS rendering of truncated images changes).

Do you still want me to remove them?

Copy link
Owner

Choose a reason for hiding this comment

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

OK, let's leave them in.

Repository owner deleted a comment from coveralls Oct 5, 2017
@lovell
Copy link
Owner

lovell commented Oct 5, 2017

I added a temporary commit 50563c4 so this PR will pass CI after the next rebase+push.

src/pipeline.cc Outdated
@@ -250,6 +250,9 @@ class PipelineWorker : public Nan::AsyncWorker {
if (shrink_on_load > 1) {
// Reload input using shrink-on-load
vips::VOption *option = VImage::option()->set("shrink", shrink_on_load);
if (baton->input->failOnError) {
Copy link
Owner

Choose a reason for hiding this comment

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

Similar question here, should the logic match? Perhaps move it into a helper? (I notice accessMethod is missing here - that looks like an existing bug though so I'll sort it later.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not going to add a helper, but I'll push this change.

@coveralls
Copy link

coveralls commented Oct 8, 2017

Coverage Status

Coverage increased (+0.006%) to 99.021% when pulling 34ed224 on mceachen:suit-failonerror into 50563c4 on lovell:suit.

Repository owner deleted a comment from coveralls Oct 8, 2017
Repository owner deleted a comment from coveralls Oct 8, 2017
Repository owner deleted a comment from coveralls Oct 8, 2017
Repository owner deleted a comment from coveralls Oct 8, 2017
@lovell lovell merged commit 87d066e into lovell:suit Oct 8, 2017
@lovell
Copy link
Owner

lovell commented Oct 8, 2017

Marvellous, thank you for all your work on this Matthew.

@lovell lovell added this to the v0.19.0 milestone Oct 8, 2017
lovell added a commit that referenced this pull request Oct 8, 2017
@mceachen
Copy link
Contributor Author

mceachen commented Oct 8, 2017

Thanks for sharp!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants