Skip to content

Better error message for bad parameter default#1805

Merged
davidism merged 4 commits into
pallets:masterfrom
MLH-Fellowship:catch-bad-default
Mar 5, 2021
Merged

Better error message for bad parameter default#1805
davidism merged 4 commits into
pallets:masterfrom
MLH-Fellowship:catch-bad-default

Conversation

@Saif807380
Copy link
Copy Markdown
Contributor

Added a try block to check whether the default value provided to an option with multiple=True is a valid iterable. If the value is not a valid iterable, a TypeError with a better error message is raised.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

Comment thread src/click/core.py Outdated
@davidism davidism added this to the 8.0.0 milestone Mar 5, 2021
Comment thread CHANGES.rst Outdated
@davidism davidism merged commit 1cb8609 into pallets:master Mar 5, 2021
@davidism davidism deleted the catch-bad-default branch March 5, 2021 14:40
@effigies
Copy link
Copy Markdown

effigies commented Mar 5, 2021

Ah, I wish I'd followed this. Would it be possible to identify which argument generated the TypeError? It looks like there's a self.name that could be used.

@davidism
Copy link
Copy Markdown
Member

davidism commented Mar 5, 2021

Both the errors raised in type_cast_value should be in __init__ instead. The composite error should be removed, and both places that value is iterated in type_cast_value should raise a BadParameter error instead of TypeError.

BadParameter adds the parameter name before the message.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traceback when CLI option has bad default could be more helpful

3 participants