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

Display error/warning for too large input #72 #168

Merged
merged 24 commits into from
Mar 22, 2019
Merged

Conversation

ongspxm
Copy link
Contributor

@ongspxm ongspxm commented Mar 7, 2019

close #72

Currently, for data that is too long, `qrCodeLib.genQr()` will return
an error "Data too long". This exception is not caught, and could be
used to display an error message, warning user that the size of data is
too large for the qr code generation.

The error could be displayed using the existing
`CommonMessages.showError()`, an advantage of tying the error messages
to the `oninput` callback is that when the data size shrinks back to
one that can fits into a qrcode, the area will show the actual qr code
for the data again.

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ongspxm,
thanks for your first contribution to this project! 🎉 👍
I hope you'll like this project and enjoy hacking on it… 😃

So the change itself looks generally good.

However, I am not sure whether it solves #72 completely.
Did you test both the SVG and Canvas version? (Which version does throw this error? Likely not both…)

Also notice you may need to move the code to the specific files for the libraries then. 😄

src/popup/modules/UserInterface.js Outdated Show resolved Hide resolved
src/popup/modules/UserInterface.js Show resolved Hide resolved
src/popup/modules/UserInterface.js Outdated Show resolved Hide resolved
@ongspxm
Copy link
Contributor Author

ongspxm commented Mar 8, 2019

@ongspxm
Copy link
Contributor Author

ongspxm commented Mar 8, 2019

ready for second round of review,

and the kjua thing is kinda hackish, my change is at the end of the min file. search for the only catch in the file

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the kjua thing is kinda hackish

As you noticed, it very obviously is… 😆

And I really don't want to maintain a forked version of kjua or so…
And also, I don't really want to review minified source code. No really…

What I see is this change:

-catch(r){if(!n.test(r.message))throw r}return null}
+catch(r){if(!(a<40&&n.test(r.message)))throw r}return null}

So why only for < 40 chars etc.??
I do not understand that change at all…

So here is what you can do:

  • get your change accepted as a PR in the upstream project: https://github.com/lrsjng/kjua/pulls (obviously, you need to explain there why you need this change etc.)
  • work around it…?
    Is not there some other functionality/difference that you can see from the outside if the length is too long? (I mean the function you changed should return null in this case?)

In any case, please revert the change to the minified kjua lib…


Also in our code base: Please don't throw strings around. When you need to catch them from dependencies (libs) you have obviously no other chance, but here I would recommend custom ES6 error types. They are used multiple times in this project and e.g. the Mastodon addon, so you can get some inspiration from there.

When you use them you can handle the specific "error catching & conversion" in the respective QrLib files and handle the actual error (i.e. showing user error etc.) in UserInterface or so…


Also small thing: Do not forget to document when a function throws something.

src/popup/modules/QrLib/kjua.js Outdated Show resolved Hide resolved
src/_locales/en/messages.json Outdated Show resolved Hide resolved
@ongspxm
Copy link
Contributor Author

ongspxm commented Mar 10, 2019

So why only for < 40 chars etc.??
I do not understand that change at all…

Haha, there is 40 versions of qrcode, each accepting more characters than the last. What the lib returns is a canvas or image. And when it runs out of the 40 versions or qrcode, it just returns a blank canvas or image.

There isnt a way of determining if its good, because from the outside, the inage is the same. I could try making a pull request to the library repo.

opened: lrsjng/kjua#12

Co-Authored-By: ongspxm <ongspxm@gmail.com>
Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then I'll let upstream some time for merging your change. As that, I mark it as blocked and hope upstream will do something.

However, your PR itself still needs some changes as commented before. (e.g. usage of error classes)

src/popup/modules/QrLib/kjua.js Outdated Show resolved Hide resolved
src/popup/modules/UserInterface.js Outdated Show resolved Hide resolved
@rugk rugk added the blocked This issue is blocked by something from the outside and cannot be done currently. label Mar 11, 2019
@rugk
Copy link
Owner

rugk commented Mar 11, 2019

BTW, marking this as blocked by lrsjng/kjua#12

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only some minor other changes...

src/popup/modules/UserInterface.js Outdated Show resolved Hide resolved
src/popup/modules/QrLib/QrError.js Outdated Show resolved Hide resolved
src/popup/modules/QrLib/kjua.js Outdated Show resolved Hide resolved
src/popup/modules/QrLib/qrgen.js Show resolved Hide resolved
@rugk
Copy link
Owner

rugk commented Mar 18, 2019

Got unblocked as lrsjng/kjua#12 has been merged 😄

As upstream also updated/changed a little more, can you update the lib to the new version and test whether it works as expected. (Also as for this change here?)

@rugk rugk removed the blocked This issue is blocked by something from the outside and cannot be done currently. label Mar 18, 2019
@rugk
Copy link
Owner

rugk commented Mar 18, 2019

And extra thing: Maybe we can mention somewhere in the source code (or file name?), which (in this case) kjua version we are using?

@rugk
Copy link
Owner

rugk commented Mar 18, 2019

It's version 0.2.0, not 2.0... 😃

@rugk
Copy link
Owner

rugk commented Mar 19, 2019

src/_locales/en/messages.json Outdated Show resolved Hide resolved
Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I noticed some regression happened:
It does not catch the exception, it just throws with the SVG lib (qrcodegen).

image

src/popup/modules/QrLib/QrError.js Outdated Show resolved Hide resolved
src/popup/modules/QrLib/QrError.js Outdated Show resolved Hide resolved
rugk and others added 2 commits March 19, 2019 23:33
Co-Authored-By: ongspxm <ongspxm@gmail.com>
@ongspxm
Copy link
Contributor Author

ongspxm commented Mar 19, 2019

@rugk thanks for the fast review, ready again

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, considering clicking "resolve conversation" on an issue, you've resolved. 😄 (Then you should also notice, if you forget a review comment. 😉)

src/popup/modules/QrLib/QrError.js Outdated Show resolved Hide resolved
src/popup/modules/QrLib/QrError.js Outdated Show resolved Hide resolved
src/popup/modules/UserInterface.js Outdated Show resolved Hide resolved
src/_locales/en/messages.json Outdated Show resolved Hide resolved
src/popup/modules/QrLib/QrError.js Outdated Show resolved Hide resolved
Co-Authored-By: ongspxm <ongspxm@gmail.com>
@rugk rugk merged commit f91faad into rugk:master Mar 22, 2019
rugk added a commit that referenced this pull request Mar 22, 2019
daaAd1 pushed a commit to daaAd1/offline-qr-code that referenced this pull request Sep 30, 2019
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.

Display error/warning for too large input
2 participants