Skip to content

Uncaught exceptions aren't catched or rejected - #111

Merged
blueimp merged 1 commit into
blueimp:masterfrom
axa-ch:bugfix/drawImage-exceptions-not-handled
May 7, 2020
Merged

blueimp merged 1 commit into
blueimp:masterfrom
axa-ch:bugfix/drawImage-exceptions-not-handled

Conversation

@AndyOGo

@AndyOGo AndyOGo commented May 6, 2020

Copy link
Copy Markdown
Contributor

fixes #110

@AndyOGo AndyOGo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please see my question.

Comment thread js/load-image-scale.js Outdated
} else if (options.imageSmoothingQuality) {
ctx.imageSmoothingQuality = options.imageSmoothingQuality
}
ctx.drawImage(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@blueimp drwaImage may throw several exceptions, like fro too huge images.

In case that happens the Promise should reject or the callback api should have an type === 'error'.
How is the best way to move this error up?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

For the Promise style API, if the result is an error, it should always reject, so your proposed solution is correct.

@AndyOGo AndyOGo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@blueimp Please see my fix for uncaught exceptions

Comment thread js/load-image.js Outdated
return
} else if (img instanceof Error) {
reject(img);
return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@blueimp reject was never called here

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I did not consider exceptions in the transformation call previously, so that's a necessary addition now that exceptions can bubble up through the resoleWrapper as well.

Comment thread js/load-image.js
Comment on lines +165 to +173

try {
loadImage.transform(img, options, callback, file, {
originalWidth: img.naturalWidth || img.width,
originalHeight: img.naturalHeight || img.height
})
} catch (error) {
callback(error)
}

@AndyOGo AndyOGo May 6, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@blueimp This should now hanlde any uncaught exceptions in any transformations, if I understood the system correctly 🤔

Edit: Meanwhile I made a local overwrite and it catches all uncaught exceptions.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, that's the right location for the try...catch wrapper. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great. Any tests you would like to be added?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think it's fine to include this with just the existing tests.

Although it would be good to test this specific scenario (huge canvas sizes) as well, the tradeoff would likely be largely increased memory requirements for running the tests.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

One other item I'm still thinking about though is that the Promise executor already has an implicit try...catch around it, so it's only necessary for the callback style.
I might add this improvement after the merge though, since it requires some restructuring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmh, I used the Promise API, but .catch() hanlder wasn't called 🤔

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You're right, the Promise executor cannot catch errors that happen asynchronously.
So everything is fine as is. :)

@AndyOGo AndyOGo changed the title fix: uncaught exceptions, still need to reject promise Uncaught exceptions aren't catched or rejected May 6, 2020
@blueimp

blueimp commented May 7, 2020

Copy link
Copy Markdown
Owner

Thanks for your report and for providing a solution @AndyOGo. :)

@blueimp

blueimp commented May 7, 2020

Copy link
Copy Markdown
Owner

One last request, please squash your commits into a single one (technically this is possible via GitHub's UI as well, but that would remove your authorship information from the commit, which I wanna avoid).

Revert "fix: uncaught exceptions, still need to reject promise"

This reverts commit 5faa5f6.

fix: catch uncaught error in scale transformation

fix: resolveWrapper never rejected errors

Revert "fix: catch uncaught error in scale transformation"

This reverts commit 8e93865.

fix: catch any transformation error

fix: prettier
@AndyOGo
AndyOGo force-pushed the bugfix/drawImage-exceptions-not-handled branch from 41b4e99 to 8e25a70 Compare May 7, 2020 11:21
@AndyOGo

AndyOGo commented May 7, 2020

Copy link
Copy Markdown
Contributor Author

@blueimp Thank you for your feedback.
I sqashed them.

@blueimp

blueimp commented May 7, 2020

Copy link
Copy Markdown
Owner

Thanks again! 👍

@blueimp
blueimp merged commit ef96f78 into blueimp:master May 7, 2020
@AndyOGo
AndyOGo deleted the bugfix/drawImage-exceptions-not-handled branch May 7, 2020 11:27
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.

Uncaught exceptions of transformations cause stale image loading

2 participants