-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 error message when trying to use SVG in image source #7313
Conversation
src/util/ajax.js
Outdated
@@ -158,10 +158,15 @@ export const getImage = function(requestParameters: RequestParameters, callback: | |||
} else if (imgData) { | |||
const img: HTMLImageElement = new window.Image(); | |||
const URL = window.URL || window.webkitURL; | |||
console.log('get image', imgData); |
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.
Leftover console.log
src/util/ajax.js
Outdated
img.onerror = () => { | ||
const err = new Error('Image sources cannot use SVG files'); | ||
callback(err); | ||
}; |
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.
Maybe let's do a shorter version?
img.onerror = () => callback(new Error('Image sources cannot use SVG files'));
src/util/ajax.js
Outdated
@@ -162,6 +162,7 @@ export const getImage = function(requestParameters: RequestParameters, callback: | |||
callback(null, img); | |||
URL.revokeObjectURL(img.src); | |||
}; | |||
img.onerror = () => callback(new Error('Image sources cannot use SVG files')); |
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.
Aren't there other possible reasons for an error here? There's no check that it was actually passed an SVG to begin with. Maybe something more general like 'Unable to load image. Please make sure you're using a supported image type like PNG or JPEG. SVGs are not supported' ?
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.
Yeah that's a good point. I'll update the error message.
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.
ty!
Launch Checklist
Fixes #7312
Superseding #5240
#5240 is out of date and it's easier just to open a new one and close that. JSDom still does not implement
URL.createObjectURL
orURL.revokeObjectURL
so there's not a good way to add a test for this. It's pretty simple though and worked as expected in manual debugging so I think no test is fine.