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?
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
messagepassed there, which meansexc.messageis defaulted toNoneby 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.NoSuchOptionhttps://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 doingstr(exc)works nicely. However,MissingParameterdoesn't have this, which means any attempt to stringify (e.g. print or log) aMissingParameteractually causes aTypeError: __str__ returned non-string (type NoneType)and then things go badly wrong.Is it expected that
MissingParameteris 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 forMissingParametererrors.TL;DR It would be nice if
MissingParameterwas printable when raised viaParameter.full_process_value(or ideally more generally).It might be enough to have something along the lines of what
NoSuchOptiondoes?