Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError exception message does not display erroneous value #2665

Closed
ptmcg opened this issue Dec 9, 2022 · 4 comments
Closed

TypeError exception message does not display erroneous value #2665

ptmcg opened this issue Dec 9, 2022 · 4 comments
Labels
help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted. needs:reproducer ideally a failing test marked as xfail. If that is not possible exact instructions to reproduce

Comments

@ptmcg
Copy link
Contributor

ptmcg commented Dec 9, 2022

Issue

After upgrading to 4.0, we are getting the following exceptions in our build pipeline:

File "/tmp/tmpw_2jv6x3/python-test-env/lib/python3.9/site-packages/tox/config/cli/parser.py", line 293, in add_color_flags
    if converter.to_bool(os.environ.get("NO_COLOR", "")):
File "/tmp/tmpw_2jv6x3/python-test-env/lib/python3.9/site-packages/tox/config/loader/str_convert.py", line 90, in to_bool
    raise TypeError(f"value {value} cannot be transformed to bool, valid: {', '.join(StrConvert.VALID_BOOL)}")

TypeError: value  cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes

We cannot reproduce the issue locally, else we would have more debugging tools and options.

The exception message is not showing us what the incorrect value is. While it appears that it might be the empty string, an empty string is included in the VALID_BOOL list, and so should not raise the TypeError. So we suspect some other value, but since it is non-printing, we cannot diagnose.

I am submitting a PR to add !r and repr() calls in the to_bool method to make the exception message clearer, so that we can better diagnose the underlying issue.

@gaborbernat gaborbernat added needs:reproducer ideally a failing test marked as xfail. If that is not possible exact instructions to reproduce help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted. labels Dec 9, 2022
@gaborbernat
Copy link
Member

We cannot reproduce the issue locally, else we would have more debugging tools and options

Can't mark this a bug until we have a reproducer.

@ptmcg
Copy link
Contributor Author

ptmcg commented Dec 9, 2022

Fair enough. I guess this is actually more like a feature request. We would like this exception message to be enhanced so that it shows the actual value that we are failing on.

@gaborbernat gaborbernat added this to the 4.0.x milestone Dec 9, 2022
@gaborbernat
Copy link
Member

Done via https://github.com/tox-dev/tox/pull/2666/files and released.

@ptmcg
Copy link
Contributor Author

ptmcg commented Dec 10, 2022

Thanks so much for your expeditious handling of this!

We can now see in our log a more helpful message:

TypeError: value '\x1b[0m' cannot be transformed to bool, ...

I suspect a command with colorized output (perhaps colorizing was a recent addition) was run using subprocess.run() or similar, the output captured and then naively parsed to extract 1, 0, Y, N, etc. but got the terminal escape sequence instead.

Now we have a solid lead to follow!

@ptmcg ptmcg closed this as completed Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted. needs:reproducer ideally a failing test marked as xfail. If that is not possible exact instructions to reproduce
Projects
None yet
Development

No branches or pull requests

2 participants