edi9999 / jsqrcode

[deprecated] Lazarsoft's jsqrcode as a node module, object oriented, and with tests
Apache License 2.0
278 stars 63 forks source link

Detect failure in the reading #20

Closed RichardsonWTR closed 8 years ago

RichardsonWTR commented 8 years ago

When the image is not good enough, I get the message: "error decoding QR Code: Couldn't find enough finder patterns"

But I am detecting the QR code inside a loop. In the LazarSoft code, when the QR code is not good enough, a exception is thrown.

How I will know when failed to read?

edi9999 commented 8 years ago

They should be an exception thrown :

https://github.com/edi9999/jsqrcode/blob/master/src/alignpat.js#L276

RichardsonWTR commented 8 years ago

Sorry my insistence, but I have not explained well :/ The message I get is inside the callback! See some samples:

error decoding QR Code: Couldn't find enough finder patterns:0 patterns found error decoding QR Code: Couldn't find enough finder patterns:1 patterns found error decoding QR Code: Couldn't find enough finder patterns:2 patterns found error decoding QR Code: Error locator degree does not match number of roots error decoding QR Code: Invalid mode: 6 in (block:0 bit:3)

But, when I adjust the image on camera correctly, the callback gets the message of the code correctly.

I have investigated the decode method and I think there is a small change to do. This line

this.result = "error decoding QR Code: " + e;

should be

throw "error decoding QR Code: " + e;

See here! https://github.com/edi9999/jsqrcode/blob/master/src/qrcode.js#L37

edi9999 commented 8 years ago

Indeed, this seems to be a problem.

The problem I think was that since the execution is async, we can't just throw here, but we have to pass the error to the callback.

edi9999 commented 8 years ago

I don't have much time to do this, maybe you can do a Pull request ?

RichardsonWTR commented 8 years ago

Sorry for the delay to reply! Take a look! #21