On 2019-09-07 19:00, Kurtis Rader wrote: > On Sat, Sep 7, 2019 at 9:08 AM Marcin Zajączkowski <msz...@wp.pl > <mailto:msz...@wp.pl>> wrote: > > Sure. I want to be able to call other command on the command failure: > > > my_command || call_error_handler > > where the error handler could be curl to https://healthchecks.io/ > > > The following script produces this result: > > *returning status 0 > status is 0 > returning status 1 > handling status 1 > status is 1 > returning status 33 > handling status 33 > status is 33 > * > > > function my_command > echo returning status $argv[1] > return $argv[1] > end > > function call_error_handler > set -l saved_status $status > echo handling status $saved_status > return $saved_status > end > > my_command 0; or call_error_handler > echo status is $status > my_command 1; or call_error_handler > echo status is $status > my_command 33; or call_error_handler > echo status is $status
Thanks. As I needed to customize the error notifications (use it will different commands) I slightly modified your function to something like: > function error_handler_wrapper > set -l saved_status $status > $argv $saved_status > return $saved_status > end Then I can write: > my_command && call_ok_handler || error_handler_wrapper call_error_command It's not perfect, there are hidden assumption about the commands, but it seems to work :). As a side effect, the "error_handler_wrapper" also covers errors in "call_ok_handler" which is nice. Marcin -- https://blog.solidsoft.info/ - Working code is not enough _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users