GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Show custom error message in prompt with `hide_input=True` by doiken · Pull Request #3256 · pallets/click

Conversation

@doiken

@doiken doiken commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

fixes #2809

prompt() with hide_input=True always showed a generic error message, even for custom types.

This change masks the input value using repr(value) matching
(consistent with built-in types' {value!r} pattern) and shows
custom messages that don't contain the input value as-is.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Rowlando13 Rowlando13 linked an issue Apr 29, 2026 that may be closed by this pull request
@click.Option with 'hide_input' = True (used for password) and custom type parameter doesn't show custom error message #2809
Closed
@Rowlando13 Rowlando13 added this to the 8.4.0 milestone Apr 29, 2026
@Rowlando13
Rowlando13 requested a review from kdeldycke April 29, 2026 06:11
@Rowlando13
Rowlando13 changed the base branch from stable to main April 29, 2026 06:52
AndreasBackx
AndreasBackx approved these changes Apr 30, 2026
View reviewed changes
Comment thread src/click/termui.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke kdeldycke changed the title fix: show custom error message in prompt with hide_input=True fix: show custom error message in prompt with hide_input=True Apr 30, 2026
@kdeldycke kdeldycke added bug prompt Interactive input and confirmation labels Apr 30, 2026
@kdeldycke
kdeldycke force-pushed the fix/hide-input-custom-error-message branch from 36a0bad to 3dac311 Compare April 30, 2026 08:12
@kdeldycke

kdeldycke commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

So exactly what I was thinking @AndreasBackx : this fix is way too naive. See the number of failing edge-cases I was able to add.

So now: either I try to fix it locally on top of that PR, or I can implement a better long-term solution. Maybe by modifying how UsageError manage the raw value. But I have not studied the consequences and impact yet.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke
kdeldycke marked this pull request as draft April 30, 2026 08:25
@AndreasBackx

AndreasBackx commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

I've got two thoughts as well. We could instead of a ValueError do a custom error like you say, but require the message to be a literal meaning you cannot interpolate the input value in it.

Or... we wrap the input value in a wrapper that has its own str and repr implementation that would obfuscate the real value. The real value would be some subfield perhaps. Though this would be a breaking change and I don't think it's very pretty.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke kdeldycke mentioned this pull request May 8, 2026
FuncParamType should use ValueError for self.fail(message) #3105
Closed
doiken and others added 2 commits May 8, 2026 16:04
@doiken @kdeldycke
fix: show custom error message in prompt with hide_input=True
a09c1c6
@kdeldycke
Demonstrate limits of substring matching
efd4daf
@kdeldycke
kdeldycke force-pushed the fix/hide-input-custom-error-message branch from 3dac311 to 3c2fc33 Compare May 8, 2026 14:41
@kdeldycke kdeldycke changed the title fix: show custom error message in prompt with hide_input=True Show custom error message in prompt with hide_input=True May 8, 2026
@kdeldycke
kdeldycke marked this pull request as ready for review May 8, 2026 14:43
@kdeldycke
kdeldycke requested review from AndreasBackx, Rowlando13 and davidism May 8, 2026 14:43
@kdeldycke
Implement a regex-based solution to hide hidden input
61bdc2a
@kdeldycke
kdeldycke force-pushed the fix/hide-input-custom-error-message branch from c5d2967 to 61bdc2a Compare May 8, 2026 14:47
@kdeldycke

kdeldycke commented May 8, 2026

Copy link
Copy Markdown
Collaborator

I've got two thoughts as well. We could instead of a ValueError do a custom error like you say, but require the message to be a literal meaning you cannot interpolate the input value in it.

Or... we wrap the input value in a wrapper that has its own str and repr implementation that would obfuscate the real value. The real value would be some subfield perhaps. Though this would be a breaking change and I don't think it's very pretty.

I think the subfield looks like the ultimate, realiable solution. But it would introduce too much changes in my opinion. And I am not sure if it will look clean or not. I propose to defer that exploration in another PR.

In the mean time, I implemented a solution based on regexp so the hidden heuristic is more robust and cover all cases. You can see the edge-cases I handle with this regexp in the associated unittests. Just pushed that on top of the PR.

So this PR is ready to be reviewed and merged unless someone has feedbacks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke kdeldycke mentioned this pull request May 8, 2026
@click.Option with 'hide_input' = True (used for password) and custom type parameter doesn't show custom error message #2809
Closed
@doiken

doiken commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks so much for taking the time to push the regex-based solution and the extra test coverage!

kdeldycke reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AndreasBackx
AndreasBackx approved these changes May 8, 2026
View reviewed changes
@Rowlando13
Rowlando13 merged commit c943271 into pallets:main May 14, 2026
11 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@AndreasBackx AndreasBackx AndreasBackx approved these changes
@kdeldycke kdeldycke Awaiting requested review from kdeldycke
@davidism davidism Awaiting requested review from davidism
@Rowlando13 Rowlando13 Awaiting requested review from Rowlando13

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

prompt Interactive input and confirmation

Projects

None yet

Milestone

8.4.0

Development

Successfully merging this pull request may close these issues.

@click.Option with 'hide_input' = True (used for password) and custom type parameter doesn't show custom error message

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@doiken @kdeldycke @AndreasBackx @Rowlando13
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.