You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the Typer documentation, with the integrated search.
I already searched in Google "How to X in Typer" and didn't find any information.
I already read and followed all the tutorials in the docs and didn't find an answer.
I already checked if it is not related to Typer but to Click.
Commit to Help
I commit to help with one of those options 👆
Example Code
importtyperfromtyperimportOptionfromtyping_extensionsimportAnnotatedapp=typer.Typer()
defcheck_passwd(passwd: str) ->str:
iflen(passwd) <8:
raisetyper.BadParameter(
"Password must be at least 8 chars long"
)
returnpasswd@app.command()defsetpasswd(
passwd: Annotated[
str,
Option(
prompt="Enter a secure password",
hide_input=True,
callback=check_passwd,
),
],
) ->None:
print(f"Your {passwd=}")
if__name__=="__main__":
app()
Description
When BadParameter("custom error msg") is raised for an option with hide_input=True, it doesn't show custom error msg, but rather a generic Error: The value you entered was invalid.. This is a known issue in Click, reported 4 months ago without any reply from the maintainers: pallets/click#2809 (the issue has all the details). I believe it could be overwritten by Typer, the problem is in the termui.py line 177.
Operating System
Linux
Operating System Details
Ubuntu 24.04
Typer Version
0.15.2
Python Version
3.12
Additional Context
When the entered value for the password is less than 8 chars, the provided code outputs:
Enter a secure password:
Error: The value you entered was invalid.
Enter a secure password:
instead of
Enter a secure password:
Error: Password must be at least 8 chars long.
Enter a secure password:
this way making it impossible to communicate to the user what was the problem (length, a set of chars, repetition, etc.)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
When
BadParameter("custom error msg")
is raised for an option withhide_input=True
, it doesn't showcustom error msg
, but rather a genericError: The value you entered was invalid.
. This is a known issue in Click, reported 4 months ago without any reply from the maintainers: pallets/click#2809 (the issue has all the details). I believe it could be overwritten by Typer, the problem is in thetermui.py
line 177.Operating System
Linux
Operating System Details
Ubuntu 24.04
Typer Version
0.15.2
Python Version
3.12
Additional Context
When the entered value for the password is less than 8 chars, the provided code outputs:
instead of
this way making it impossible to communicate to the user what was the problem (length, a set of chars, repetition, etc.)
Beta Was this translation helpful? Give feedback.
All reactions