-
-
Notifications
You must be signed in to change notification settings - Fork 922
Uncaught exceptions aren't catched or rejected #111
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
Uncaught exceptions aren't catched or rejected #111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my question.
js/load-image-scale.js
Outdated
} else if (options.imageSmoothingQuality) { | ||
ctx.imageSmoothingQuality = options.imageSmoothingQuality | ||
} | ||
ctx.drawImage( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
js/load-image.js
Outdated
@@ -45,6 +45,9 @@ | |||
// Not using Promises | |||
if (resolve) resolve(img, data) | |||
return | |||
} else if (img instanceof Error) { | |||
reject(img); | |||
return; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
||
try { | ||
loadImage.transform(img, options, callback, file, { | ||
originalWidth: img.naturalWidth || img.width, | ||
originalHeight: img.naturalHeight || img.height | ||
}) | ||
} catch (error) { | ||
callback(error) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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. :)
Thanks for your report and for providing a solution @AndyOGo. :) |
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
41b4e99
to
8e25a70
Compare
@blueimp Thank you for your feedback. |
Thanks again! 👍 |
fixes #110