mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
![]() ### Goals * Make callable aliases transparent. * Catch errors in callable aliases and show the name of the source. * Show additional attributes: thredable, capturable. * Closes #5266 ## Exception ### Before ```xsh aliases['cd'] # <function xonsh.dirstack.cd> aliases['trace'] # <function xonsh.aliases.trace> aliases['null'] = lambda: 1/0 null # ZeroDivisionError: division by zero @aliases.register('catch') @aliases.register('me') @aliases.register('if') @aliases.register('you') @aliases.register('can') def _exc(args, stdin, stdout): for line in stdin.readlines(): print(line.strip() + '!', file=stdout, flush=True) return 1/0 if 'i' in $__ALIAS_NAME else 0 echo hey | catch | me | if | you | can # ZeroDivisionError: division by zero <--- ??? # hey!!!!! ``` ### After ```xsh aliases['cd'] # FuncAlias({'name': 'cd', 'func': 'cd'}) aliases['trace'] # FuncAlias({'name': 'trace', 'func': 'trace', '__xonsh_threadable__': False}) $XONSH_SHOW_TRACEBACK=False $RAISE_SUBPROC_ERROR = False aliases['null'] = lambda: 1/0 null #Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-15', 'func': FuncAlias({'name': 'null', 'func': '<lambda>'}), 'alias': 'null', 'pid': None} #ZeroDivisionError: division by zero @aliases.register('catch') @aliases.register('me') @aliases.register('if') @aliases.register('you') @aliases.register('can') def _exc(args, stdin, stdout): for line in stdin.readlines(): print(line.strip() + '!', file=stdout, flush=True) return 1/0 if 'i' in $__ALIAS_NAME else 0 echo hey | catch | me | if | you | can # Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-8', 'func': FuncAlias({'name': 'if', 'func': '_exc'}), 'alias': 'if', 'pid': None} # ZeroDivisionError: division by zero # hey!!!!! ``` ## Superhelp ### Before ```xsh @aliases.register("hello") def _alias_hello(): """Show world.""" print('world') hello? # No manual entry for hello ``` ### After ```xsh @aliases.register("hello") def _alias_hello(): """Show world.""" print('world') hello? # FuncAlias({'name': 'hello', 'func': '_alias_hello'}): # Show world. ``` ## 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> |
||
---|---|---|
.. | ||
appimage_py311.rst | ||
downgrade_ptk.rst | ||
env_completion.rst | ||
fix_print_exception.rst | ||
fix_process_traceback.rst | ||
funcalias.rst | ||
jobs_catch_no_process.rst | ||
jobs_repr.rst | ||
jupytext.rst | ||
main_d.rst | ||
mini_refactor.rst | ||
no_env.rst | ||
popen_name.rst | ||
shell_type.rst | ||
subproc_output_format.rst | ||
TEMPLATE.rst | ||
trace_subproc.rst | ||
waitpid_returncode.rst | ||
xonfig_env.rst | ||
zulip.rst |