passing error back to decodeSingle through callbacks #362
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I replaced the
exit(1);
call inloadImages
inside ofInputStream.createImageStream
with a callback as a way to pass the error back to the caller. It has to be propagated back through the call stack in order for the caller to see it, so I've added callbacks through each layer or used existing callbacks to pass it along. It goes all the way back to theQuagga.decodeSingle
call, which is what I'm focused on.The error stops being propagated inside of
decodeSingle
, since that is a more public API that I'm not sure about changing now. The callback that's passed in normally accepts one argument, where the user would get a result back. If there is an error, the result will beundefined
, since that is what I've seen when the code is not detected and a barcode is not located. Standard practice with Error-first Callbacks, though, would be to return the error as the first argument and give the result as the second. If we are willing to change the API for users, this is what I'd recommend.I've written these changes mainly to the
lib/quagga.js
file, which is used when the project is imported as an NPM package. It looks like there is the same original duplicate code in a number of places, and I couldn't see if there was a single source of truth for code and a way to replicate it, so I made the changes that would get this working for me in Node. Please let me know if there is a proper way of defining these changes and replicating them where it is copied or generating them.Fixes #359