-
Notifications
You must be signed in to change notification settings - Fork 6k
Improve InvalidToken Error Message
#3167
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
Conversation
Bibo-Joshi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the ideas! but I'd really like to avoid false positives here. Even the current checks make assertions that are not build on explicitly documented behavior:
- token not containing spaces is not documented (but that's sure to make sense)
- part before
:being all digits is not documented (that's almost sure as well, as it's the bots user id) - part before
:being >= 3 is not documented. I've never seen user ids shorter than 5 I think, but still …
checking for invalid characters in addition seems a bit risky to me, tbh … unless ofc I missed some documentation on that …
yeah, we were already checking that before, so it's safe by now.
yeah I'm not sure why we were checking for that. Since it's just the bot id I'd be okay for deleting this check altogether.
Yeah, I'll open an issue in the bot api repo for this soon and see if I get a concrete answer. |
|
Well so the reply received in the issue above is not what I expected.. but I have another idea: We could suggest to the user what went wrong with their token after receiving an error from What do you think? |
|
TBH, the answer makes me rather question if it's worth to keep the |
Deletes the
Bot._validate_tokenstep since bot tokens could change in the future. Now whenever anInvalidTokenexception is raised, the token is printed along with it so the user can see where they went wrong.Original proposal:
Improves PTB's verification of bot tokens and also adds a better error message along the way. Suppose your bot token is
123456:AAF5_-y.ert. So the error message now shows:We could also add another check where we assert that the no. of chars after
:is34or35. I say34since in https://core.telegram.org/bots/#creating-a-new-bot it's 34, but I have only seen it be 35 though. I didn't add this since it might be too strict and could have false positives in the future?Checklist for PRs
.. versionadded:: version,.. versionchanged:: versionor.. deprecated:: versionto the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)AUTHORS.rst(optional)__all__s