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

passing error back to decodeSingle through callbacks #362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dvoraqs
Copy link

@dvoraqs dvoraqs commented Mar 19, 2019

I replaced the exit(1); call in loadImages inside of InputStream.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 the Quagga.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 be undefined, 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

@ericblade
Copy link
Collaborator

@dvoraqs Hi there! I've forked this project at https://github.com/ericblade/quagga2 and intend to maintain it going forward. I'd love to review your contribution there!

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

Successfully merging this pull request may close these issues.

Node exits on Invalid File Signature with certain images
2 participants