Skip to content

Unprintable MissingParameter exception #1139

@tom-dalton-fanduel

Description

@tom-dalton-fanduel

My code is (correctly) hitting https://github.com/pallets/click/blob/master/click/core.py#L1444 and raising a MissingParameter exception. However, there's no message passed there, which means exc.message is defaulted to None by the base class (ClickException) constructor here https://github.com/pallets/click/blob/master/click/exceptions.py#L23.

With other ClickExceptions I've seen (e.g. NoSuchOption https://github.com/pallets/click/blob/master/click/exceptions.py#L165), if message is set to None then it gets reset as something more sensible e.g. "No such option 'foo'". This means that doing str(exc) works nicely. However, MissingParameter doesn't have this, which means any attempt to stringify (e.g. print or log) a MissingParameter actually causes a TypeError: __str__ returned non-string (type NoneType) and then things go badly wrong.

Is it expected that MissingParameter is an unprintable exception when caused e.g. by missing out a required argument? It seems odd that no one else has come across this before. I'm using click in a slightly unusual context in that I'm using the group/command/arg/option parsing stuff outside of a traditional command line script, which might be why no one has seen this if click does it's own special handling for MissingParameter errors.

TL;DR It would be nice if MissingParameter was printable when raised via Parameter.full_process_value (or ideally more generally).

It might be enough to have something along the lines of what NoSuchOption does?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions