-
-
Notifications
You must be signed in to change notification settings - Fork 519
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
Display exit code with InvocationErrors #760
Conversation
Issue tox-dev#290. Co-authored-by: Daniel Hahler <git@thequod.de>
Codecov Report
@@ Coverage Diff @@
## master #760 +/- ##
==========================================
- Coverage 94.88% 94.82% -0.06%
==========================================
Files 11 11
Lines 2386 2397 +11
==========================================
+ Hits 2264 2273 +9
- Misses 122 124 +2
Continue to review full report at Codecov.
|
tox/__init__.py
Outdated
try: | ||
self.exitcode = args[1] | ||
except IndexError: | ||
self.exitcode = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be a little more clear as:
def __init__(self, command, exitcode=None):
super(Error, self).__init__(command, exitcode)
self.command = command
self.exitcode = exitcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot. Just had to use exception.Error
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops yeah, sorry my sample wasn't completely copy-pastable 😆
str_ += " (exited with code %d)" % (self.exitcode) | ||
if self.exitcode > 128: | ||
str_ += ("\nNote: On unix systems, an exit code larger than 128 " | ||
"often means a fatal error (e.g. 139=128+11: segmentation fault)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>128
means it exited due to a fatal signal
You can see the various signals that might trigger this in the table at the bottom of this
We could also compute this and show it to the user:
$ python -c 'import time; time.sleep(100)'
^\Quit (core dumped)
$ echo $?
131
$ python -c '
> import signal
> sigs = {n: s for s, n in vars(signal).items() if s.startswith("SIG")}
> print(sigs[131 - 128])
> '
SIGQUIT
A KeyError
on sigs
(in my example) means it's probably not a fatal signal that killed it (also note that although ^C
sends SIGINT -- python sets a signal handler for this and reraises it as KeyboardInterrupt
leading to an exit code of 1
instead of the expected 130
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the link, added to the documentation that was in preparation.
Giving the signal value/name could be nice, since python uses directly the relevant signals.h
; got to think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: subprocess actually returns negative exit codes for signals.
See #1401 for a followup/fix.
@gaborbernat I had an outstanding issue, I don't think this was ready for merge |
This reverts commit c1db8a8.
@asottile which one? |
I suggested an alternate wording and some additional helpful output here |
Summary: done, works, but could be better. About the proposed wording "means it exited due to a fatal signal", it is true that "signal" is more precise than "error". Finally, the wording "fatal error signal" of faqs.org, seems good (especially for segmentation fault, since it originates from an error in the program, in the first place). The note now gives the corresponding signal if one is found, hopefully matching your suggestion. Now testing the Questions: Finally, a minor question from the initial post is still pending:
|
@ederag I think it's because the PR is closed, please open a new one 👍 adding test dependencies is fine |
Waiting for revert-760-exitcode to be merged into master. |
no need to have the merge revert, just create a PR against the master. |
Strange. If you won't merge |
Was a miss click creation of that branch, sorry if it caused confusion, the revert was never merged on master https://github.com/tox-dev/tox/commits/master, I consider the extra changes here an improvement over what we have here. Hence why saying just create a new PR 👍 |
`subprocess` reports a negative exit code for signals (the assumption in tox-dev#760 (comment) was wrong). TODO: - [ ] faster test (takes >3s)
`subprocess` reports a negative exit code for signals (the assumption in tox-dev#760 (comment) was wrong). TODO: - [ ] faster test (takes >3s)
This is a PR for @blueyed patch (Issue #290), supplemented with tests.
For exit codes larger than 128, a hint is given: on unix systems this often means a fatal error.
(Not always, since an application might exit with a large custom error code)
Not showing this hint for windows platform was considered, but discarded to keep code short and
simplify tests.
Before:
After:
or, for an exit code larger than 128:
To generate these outputs, a section was added to
tox.ini
:and run with
python3 -m tox -e exitcode
.The modified section is too specific to be included in the PR, isn't it ?
Tests have been added to
test_z_cmdline.py
.Safely replacing these tests with faster ones (mock) would require someone experienced with this technique.
The documentation might be completed (still have to think about it).
Probably add a section "Understanding InvocationError exit codes"
in example/general.html
with links to
pytest
exit codes, to http://www.faqs.org/docs/abs/HTML/exitcodes.html,and explaining that no exit code is shown when the process has been aborted (like Qt does).
And for good measure, giving a link to ignoring-a-command-exit-code.
Contribution checklist:
in message body
<issue number>.<type>.rst
for example (588.bugfix.rst)<type>
is must be one ofbugfix
,feature
,deprecation
,breaking
,doc
,misc
CONTRIBUTORS
(preserving alphabetical order)