'command-not-found-handle' and 'file-not-found-handle' behavior

3 views
Skip to first unread message

Dieter Van Eessen

unread,
Jan 18, 2018, 8:36:07 AM1/18/18
to xonsh
Hello,

One of the reasons I'm trying the switch to xonsh is better exception management. In bash I used command-not-found-handle which was builtin behavior (for bash only). There is NO such thing as 'file-not-found-handle' in bash, though it has been suggested by others many years ago.

Xonsh's event system doesn't seem to provide a solution for this, I'm currently considering the following options:
- I could try to do what I need as on_precommand and somehow skip the rest of xonsh's command execution, but that would defeat the purpose of using xonsh in the first place.
- I could modify xonsh source code and add another event 'on_failed_command'. I would have to execute run_compiled_code in a try-except block and run on_failed_command as exception. Problem is that by then python's 'exec' has already printed output to stdout/stderr (I guess). I'd also like to keep all modifications in my own code base (and leave xonsh untouched)
- I could try to modify the execution context: I see that <shell>.ctx is used as 'globals' dictionary provided to python's builtin 'exec' function (somewhere in 'run_compiled_code'). I would somehow modify 'XonshCalledProcessError' and 'FileNotFoundError' from this dictionary to point to an exception created in my .xonshRC file. This modification should occur in my RC file. Still figuring out if this gives problems (since some objects, like the execer are created before RC files are parsed).

Are there any suggestions on which path to follow?
Truly hope to get an answer. The IRC channel seems not to be very active (on the times I tried)

kind regards,
Dieter


Reply all
Reply to author
Forward
0 new messages