image-data-uri
image-data-uri copied to clipboard
Proposal: Exceptions and Error Codes
It would be great for the module, when it encounters an error, to throw
an Error
object containing a documented error code.
This would enable user code to reliably try... catch
each module method and handle each error type specifically. Currently, this is not possible, with each method returning null
on error, and the error information being displayed separately with console.log
.
I'd be happy to implement this myself but I don't currently have the time on my hands. So, I thought it prudent to raise the issue here as a matter of recordkeeping if nothing more.
By the way, thanks to @DiegoZoracKy for providing this module. It's great. 👍
Hi @ChrisTalman, I'm sorry for taking so long to give you an answer. I totally missed this. The code of this module is very old (I believe this is the first module I published), and its style is really missing some important parts as you pointed out. You are totally right.
The promise based methods are already properly using reject in case of errors, and are not logging anything. The methods decode
and encode
should indeed return Error
without sending anything out to stdout
(console.log). Would you like to send a PR with this changes? Don't worry if you don't have the time. Just let me know.
Thanks 👍
Hey @DiegoZoracKy. Thanks for getting back to me. Sadly I don't have the time right now.
I'll try to take a look at this on the following weeks. Thanks for opening this issue.