-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
Added FuncAlias #5366
Added FuncAlias #5366
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@jnoortheen what do you think? |
|
@jnoortheen sorry, I'm not clearly understand what you mean. Please give me some pointers.
|
# Lastly, a 3-tuple return value can be used to include an integer
# return code indicating failure (> 0 return code). In the previous
# examples the return code would be 0/success.
return (None, "I failed", 2)
|
@jnoortheen Thank you for the link! Why we are talking about |
It shows the error message in a specific way. e.g. |
@gforsyth It's ready to review. One question: what do you think is it possible to print full traceback with the error line? |
Can you give me an example of what you're thinking of? |
@gforsyth yep, I mean when I'm doing this: def f():
1/0
class qwe:
def __init__(self,g):
self.f=g
def __call__(self):
self.f()
try:
qwe(f)()
except Exception:
raise I have full traceback in Python: Traceback (most recent call last):
File "/private/tmp/1.py", line 9, in <module>
qwe(f)()
File "/private/tmp/1.py", line 7, in __call__
self.f()
File "/private/tmp/1.py", line 2, in f
1/0
~^~
ZeroDivisionError: division by zero But: $XONSH_SHOW_TRACEBACK = True
@aliases.register('f')
def _f():
1/0
echo f1f1f1 ; f ; echo f2f2f2 Returns only: Traceback (most recent call last):
File "/Users/pc/git/xonsh/xonsh/procs/proxies.py", line 475, in run
r = self.f(self.args, sp_stdin, sp_stdout, sp_stderr, spec, spec.stack)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pc/git/xonsh/xonsh/aliases.py", line 87, in __call__
return self.func(*func_args)
^^^^^^^^^^^^^^^^^^^^^ |
There's probably a way to do that by intercepting the traceback and then adding to it with |
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 haven't had time to figure out where this bug is coming from, but this PR introduces a strange behavior where we swallow the first traceback after setting $XONSH_SHOW_TRACEBACK=True
gil@stravaig ~ @ def _f():
................ 1 / 0
................
gil@stravaig ~ @ aliases['f'] = _f
gil@stravaig ~ @ f
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
ZeroDivisionError: division by zero
Exception in FuncAlias({'name': 'f', 'func': <function _f at 0x7def51916c20>})
gil@stravaig ~ @ $XONSH_SHOW_TRACEBACK = True
gil@stravaig ~ @ f # <- Notice no output here
gil@stravaig ~ @ f
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/home/gil/mambaforge/lib/python3.10/site-packages/xonsh/aliases.py", line 87, in __call__
return self.func(*func_args)
File "<stdin>", line 2, in _f
ZeroDivisionError: division by zero
Exception in FuncAlias({'name': 'f', 'func': <function _f at 0x7def51916c20>})
@gforsyth I think this behavior is not from this PR. There is general issue around raising exception from alias and having hard exception from closed descriptor - #5393 |
This is on current gil@stravaig ~ @ xonfig
+-----------------------------+---------------------+
| xonsh | 0.16.0.dev91 |
| Git SHA | 4a2cfc64 |
| Commit Date | May 6 14:20:34 2024 |
| Python | 3.10.12 |
| PLY | 3.11 |
| have readline | True |
| prompt toolkit | 3.0.39 |
| shell type | prompt_toolkit |
| history backend | json |
| pygments | 2.16.1 |
| on posix | True |
| on linux | True |
| distro | ubuntu |
| on wsl | False |
| on darwin | False |
| on windows | False |
| on cygwin | False |
| on msys2 | False |
| is superuser | False |
| default encoding | utf-8 |
| xonsh encoding | utf-8 |
| encoding errors | surrogateescape |
| xontrib | [] |
| RC file | [] |
| UPDATE_OS_ENVIRON | False |
| XONSH_CAPTURE_ALWAYS | False |
| XONSH_SUBPROC_OUTPUT_FORMAT | stream_lines |
| THREAD_SUBPROCS | True |
| XONSH_CACHE_SCRIPTS | True |
+-----------------------------+---------------------+
gil@stravaig ~ @ def _f():
................ 1 / 0
gil@stravaig ~ @ aliases['f'] = _f
gil@stravaig ~ @ f
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-15', 'func': '_f', 'alias': 'f', 'pid': None}
ZeroDivisionError: division by zero
gil@stravaig ~ [1] @ $XONSH_SHOW_TRACEBACK = True
gil@stravaig ~ @ f
Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-22', 'func': '_f', 'alias': 'f', 'pid': None}
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/home/gil/mambaforge/lib/python3.10/site-packages/xonsh/procs/proxies.py", line 540, in run
r = self.f(self.args, sp_stdin, sp_stdout, sp_stderr, spec, spec.stack)
File "/home/gil/mambaforge/lib/python3.10/site-packages/xonsh/procs/proxies.py", line 290, in proxy_zero
return f()
File "<stdin>", line 2, in _f
ZeroDivisionError: division by zero
gil@stravaig ~ [1] @ f
Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-27', 'func': '_f', 'alias': 'f', 'pid': None}
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/home/gil/mambaforge/lib/python3.10/site-packages/xonsh/procs/proxies.py", line 540, in run
r = self.f(self.args, sp_stdin, sp_stdout, sp_stderr, spec, spec.stack)
File "/home/gil/mambaforge/lib/python3.10/site-packages/xonsh/procs/proxies.py", line 290, in proxy_zero
return f()
File "<stdin>", line 2, in _f
ZeroDivisionError: division by zero This is on this PR branch: gil@stravaig ~ @ xonfig
+-----------------------------+---------------------+
| xonsh | 0.16.0.dev134 |
| Git SHA | 1b5c30b9 |
| Commit Date | May 7 18:45:11 2024 |
| Python | 3.10.12 |
| PLY | 3.11 |
| have readline | True |
| prompt toolkit | 3.0.39 |
| shell type | prompt_toolkit |
| history backend | json |
| pygments | 2.16.1 |
| on posix | True |
| on linux | True |
| distro | ubuntu |
| on wsl | False |
| on darwin | False |
| on windows | False |
| on cygwin | False |
| on msys2 | False |
| is superuser | False |
| default encoding | utf-8 |
| xonsh encoding | utf-8 |
| encoding errors | surrogateescape |
| xontrib | [] |
| RC file | [] |
| UPDATE_OS_ENVIRON | False |
| XONSH_CAPTURE_ALWAYS | False |
| XONSH_SUBPROC_OUTPUT_FORMAT | stream_lines |
| THREAD_SUBPROCS | True |
| XONSH_CACHE_SCRIPTS | True |
+-----------------------------+---------------------+
gil@stravaig ~ @ def _f():
................ 1 / 0
................
gil@stravaig ~ @ aliases['f'] = _f
gil@stravaig ~ @ f
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
ZeroDivisionError: division by zero
Exception in FuncAlias({'name': 'f', 'func': <function _f at 0x77d7466c3370>})
gil@stravaig ~ @ $XONSH_SHOW_TRACEBACK = True
gil@stravaig ~ @ f
gil@stravaig ~ @ f
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
File "/home/gil/mambaforge/lib/python3.10/site-packages/xonsh/aliases.py", line 87, in __call__
return self.func(*func_args)
File "<stdin>", line 2, in _f
ZeroDivisionError: division by zero
Exception in FuncAlias({'name': 'f', 'func': <function _f at 0x77d7466c3370>}) |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@gforsyth hey!
Thanks! |
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.
Nice work on this, @anki-code !
In #5366 we removed partial_proxy. But @doronz88 [found the case](https://xonsh.zulipchat.com/#narrow/stream/435525-xonsh-xontrib/topic/.E2.9C.94.20xontrib-z.20and.20maybe.20other.20break.20in.20master) where this functionality is good and needed. In xontrib-z there is a [handler](https://github.com/AstraLuma/xontrib-z/blob/a40abb4d8b00fcc54877647ba64cf94bcb55b0a5/xontrib/z.py#L225-L227) that requires partial_proxy. So I bring partial_proxy back because it looks useful. ## For community ⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment** --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Goals
Exception
Before
After
Superhelp
Before
After
For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 comment