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

createTexture: improved error message #149

Open
jamesplease opened this issue Oct 30, 2019 · 2 comments
Open

createTexture: improved error message #149

jamesplease opened this issue Oct 30, 2019 · 2 comments

Comments

@jamesplease
Copy link
Contributor

First off...thank you for creating twgl! It's been a joy to use. One of the features I'm particularly fond of is how informative createTexture (and the related texture APIs are) when it comes to errors. It's incredibly useful how they let you know which images fail to load.

I think a small change could make those errors even more useful. Right now, the messages are returned as a string, like:

[
  "couldn't load image: /my-image.png"
]

This is a convenient format for humans to understand, but it's not particularly useful to parse programmatically.

What I'd like to do is catch when there are problems, and re-try the requests. Doing that right now requires parsing the string, which feels a bit brittle.

I'm wondering if it would make sense to return the errors in an object format; perhaps something like this:

[
  {
    type: 'IMAGE_FAILED',
    url: '/my-image.png',
    description: "couldn't load image: /my-image.png"
  }
]

This combines the best of both worlds: all of the information a computer needs to know to retry, and a human-readable response.

This would be a breaking change if the messages were just swapped wholesale, so if backwards compatibility is a concern, then perhaps that could be alleviated with a new API. Some ideas are:

createTextures(gl, things, cb, {
  detailedError: true  
});

or:

createTextures(gl, things, cb, {
  formatError(errorObject) {
    // return whatever object you want
  }
});

What do you think? Thanks for reading!

@greggman
Copy link
Owner

What errors do you actually expect to catch? The only one twgl actually handles is failure to download image. It doesn't check for any other errors so as it is the callback only has one type of error.

@jamesplease
Copy link
Contributor Author

jamesplease commented Oct 31, 2019

It makes sense that there's only one error type, which is OK. That's the one that I'm trying to detect: determine when an image fails, and knowing which URL is the culprit so that I can retry the request.

The type field of the error is not particularly important. It does allow for more than one error, but if there is only one then it can be omitted. The value in separating out the url from the human-readable message is the main thing I was tryna communicate ✌️

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

No branches or pull requests

2 participants