fish-shell icon indicating copy to clipboard operation
fish-shell copied to clipboard

Return is not setting `$status` correctly when run from a script or function

Open kemelzaidan opened this issue 1 year ago • 2 comments

I was trying to fix this issue in Oh-My-Fish project: https://github.com/oh-my-fish/oh-my-fish/issues/584

But I saw that the oh-my-fish code was returning the variable $OMF_INVALID_ARG which is set to 3. After debugging a little further, I went to the return documentation on fish to see if I was missing something and saw that the example on the documentation was also not working properly.

$ function false
    return 1
end
$ echo $status
0

So, I can only say it's probably a bug in fish itself... Please, let me know if you need any more details.

Environment:

Linux piolin 6.10.2-3-rt14-MANJARO #1 SMP PREEMPT_RT Wed Aug  7 16:22:37 UTC 2024 x86_64 GNU/Linux
$TERM = xterm-256color
sh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= fish'                                 qui 03 out 2024 11:10:55
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
kemel@piolin /home/kemel/.local/share/omf/pkg/omf/functions/packages ((v7))>

kemelzaidan avatar Oct 03 '24 14:10 kemelzaidan

The example works ok, but it needs to be invoked first.

> function false; return 1; end
> false
> echo $status
1

zanchey avatar Oct 03 '24 14:10 zanchey

Before jumping to the conclusion that return is mostly broken, I'd check the code at hand.

Here, it appears like "omf.packages.install" is called from "omf.cli.install", where it is immediately used in an and, and the return status then unused:

https://github.com/oh-my-fish/oh-my-fish/blob/62204b02c3643def0707a28af64bdb032ef5e069/pkg/omf/functions/cli/omf.cli.install.fish#L12-L15

This has a $fail_count, but it is not set until after a bunch of other things run.

faho avatar Oct 04 '24 13:10 faho

Closing because answers have been provided and no user feedback has been given. We can re-open if needed.

mqudsi avatar Nov 14 '24 19:11 mqudsi