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

loadImageFromFile and loadImageFromURL silently fail for unrecognized image formats #116

Closed
dxoxp opened this issue Jan 4, 2019 · 2 comments
Assignees
Labels

Comments

@dxoxp
Copy link

dxoxp commented Jan 4, 2019

Version

tui-image-editor.js 3.3.0

Development Environment

Windows 7
Chrome 71
Firefox 64

Current Behavior

Attempting to load unrecognized image formats cause an exception in the image editor that cannot be caught.

Normally one would attempt to use loadImageFromFile or loadImageFromURL in a promise construct like:

imageEditor.loadImageFromFile(x)
	.then( function() {
		// Do "success" processing
	})
	.catch( function() {
		// Do "failure" processing
	} );

However, if the image cannot be successfully loaded, the image editor throws and exception that bypasses the ".catch()" function.

Also, wrapping the loadImageFromFile in a native try/catch handler does not help either.

This behavior makes it difficult to know if the editor actually loaded the image successfully.

Steps to Reproduce:

  1. Open the URL http:https://ui.toast.com/tui-image-editor/ in a browser.
  2. Click the "Load" button and choose a text file. (This also happens for image file formats that the particular browser does not understand.)
  3. Notice that the Promise's ".catch()" function is not executed.
  4. Notice that the editor produces an exception in the browser console.
Uncaught TypeError: Cannot read property 'getElement' of null
    at tui-image-editor.js:15184
    at klass.<anonymous> (fabric.js:6411)
    at HTMLImageElement.img.onerror (fabric.js:642)

Suggestion:

On line 15184 of dist/tui-image-editor.js, the following code is found:

	if (oImage.getElement()) {
		resolve(oImage);
	} else {
		reject(rejectMessages.loadingImageFailed);
	}

Consider enhancing the test to

	if (oImage && oImage.getElement()) {

This allows the promise to be rejected and handled by the client code.

Expected Behavior

The .catch function for the promises returned by loadImageFromURL and loadImageFromFile should be called if the image cannot be loaded.

@T-vK
Copy link

T-vK commented Jan 7, 2019

I just ran into the same issue. I'd really like to see this getting fixed.

@junghwan-park
Copy link
Member

@dxoxp @T-vK
I got this. Thanks! 👍

@junghwan-park junghwan-park self-assigned this Jan 18, 2019
HerlinMatos pushed a commit to EveryMundo/tui.image-editor that referenced this issue Jul 2, 2020
* fix: Check oImage existence before use fixes nhn#116

* fix: Add rejectMessage for 'loadingImageFailed'

* chore: Add missing message and order messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants