-
-
Notifications
You must be signed in to change notification settings - Fork 632
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
fix: Suppress subprocess traceback in case XONSH_SHOW_TRACEBACK=False and $RAISE_SUBPROC_ERROR=True #5066
fix: Suppress subprocess traceback in case XONSH_SHOW_TRACEBACK=False and $RAISE_SUBPROC_ERROR=True #5066
Conversation
This PR aims to propose an initial implementation for hide the traceback when using |
Hello and welcome! echo @("""
$XONSH_SHOW_TRACEBACK = False
$RAISE_SUBPROC_ERROR = True
print('LINE 1')
cp nonexisting_file.txt other_name.txt
print("LINE 2")
""") > /tmp/1.xsh
xonsh /tmp/1.xsh
# Here should be only "LINE 1" and the short version of error. |
thanks for the review @anki-code , I will fix that! thanks! |
@anki-code with traceback disable
with traceback active
btw, I am using here sys.exit .. is there another way? |
tomorrow I will fix/update the tests. |
1e93fe3
to
af95a21
Compare
@anki-code I was able to remove the sys.exit .. but not sure if that is a good alternative ... btw, the pre-commit.ci erros look not related to this PR .. but if I am wrong, I would be happy to fix that. |
hey everyone! I think this PR is ready for review .. would appreciate any suggestion to improve this PR :) thanks! |
Codecov Report
@@ Coverage Diff @@
## main #5066 +/- ##
==========================================
+ Coverage 66.23% 66.77% +0.53%
==========================================
Files 129 129
Lines 23829 23831 +2
Branches 4500 4501 +1
==========================================
+ Hits 15784 15912 +128
+ Misses 6800 6691 -109
+ Partials 1245 1228 -17
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@xmnlab the changes look good. Could you fix the failing flake8 checks ? |
thanks for the review @jnoortheen .. I can take a look if there is anything caused by my PR .. but most of the issues camed from upstream: b600c58 |
Stop |
@xmnlab good then. Thanks for the PR and welcome to the Xonsh community as a contributor. |
@anki-code what has happened? |
I've tested the changes and I see we lost the reference to the line that causes error. Now: pip install git+https://github.com/xmnlab/xonsh@hide-traceback-for-RAISE_SUBPROC_ERROR
xonsh
echo @("""
$XONSH_SHOW_TRACEBACK = False
$RAISE_SUBPROC_ERROR = True
print('LINE 1')
cp nonexisting_file.txt other_name.txt
print("LINE 2")
""") > /tmp/1.xsh
xonsh /tmp/1.xsh
# LINE 1
# cp: cannot stat 'nonexisting_file.txt': No such file or directory Expected output: # LINE 1
# cp: cannot stat 'nonexisting_file.txt': No such file or directory
# File "/tmp/1.xsh", line 6, in <module> <<<<<<<<<<<<<<<<<<<<<
# cp nonexisting_file.txt other_name.txt <<<<<<<<<<<<<<<<<<<<< Without this the debugging is very uncomfortable. Can we add the line number with the error? |
Yes it should show that info. I think the first line of the traceback has that info. In the if-clause we can add else branch to show the first line of the traceback |
Please add. |
ok I can open a follow up PR for that! thanks! |
My current suggestion is if XSH.env.get("XONSH_SHOW_TRACEBACK"):
traceback.print_exception(*exc_info)
else:
traceback.print_exception(*exc_info, limit=1) but this will print more lines. It would need to be formatted. |
… and $RAISE_SUBPROC_ERROR=True (xonsh#5066) * fix: Add and extra condition for print traceback from subprocess * add news * Apply pre-commit hooks * Fix initial implementation using sys.exit * Update pr-5066.rst * Remove sys.exit --------- Co-authored-by: Andy Kipp <anki-code@users.noreply.github.com>
Don't show the traceback for
RAISE_SUBPROC_ERROR
whenXONSH_SHOW_TRACEBACK
is false.#4708
For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 comment