Skip to content
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

move fish_command_not_found exit code and redirection handling up to the error handler function #9517

Closed

Conversation

jhheider
Copy link

Description

This moves the choice of redirection to stderr and the 127 exit code up to the error handler function if defined. Fallback code unchanged. Default error handler config is also updated to maintain backwards compatibility. This matches, as best I can tell, the behavior of zsh/bash. fixes pkgxdev/pkgx#344

Fixes issue #7902

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@jhheider
Copy link
Author

Looks like I have some tests to fix. But input on whether this is desired/acceptable/usable style is welcome.

Comment on lines +7 to +14
$fish -C 'function fish_command_not_found; echo cmd-not-found; end' -c "nonexistent-command-1234 1 2 3 4"
##CHECKERR: cmd-not-found
#CHECKERR: fish: Unknown command: nonexistent-command-1234
#CHECKERR: nonexistent-command-1234 1 2 3 4
#CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~^
$fish -C 'function fish_command_not_found; echo command-not-found $argv; end' -c "nonexistent-command-abcd foo bar baz"
#CHECKERR: command-not-found nonexistent-command-abcd foo bar baz
#CHECKERR: fish:
##CHECKERR: command-not-found nonexistent-command-abcd foo bar baz
#CHECKERR: fish: Unknown command: nonexistent-command-abcd
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a regression, unfortunately. need to figure out why this particular needed case fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails because this runs a fish - $fish above - that isn't interactive.

So because you only made it execute fish_command_not_found if fish is interactive, and this tries to override fish_command_not_found, it no longer works.

I'm not sure if that's okay.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm not 100% that this doesn't need more tweaks, but I felt it was a start. A bunch of the error responses changed because the error return was moved to the fish function itself, rather than propagating out of the C++ (as far I understood it). Help is absolutely welcome.

Comment on lines -30 to +29
# CHECKERR: {{.*}}: Unknown command: '{ echo; echo }'
# CHECKERR: {{.*}}: '{ ... }' is not supported for grouping commands. Please use 'begin; ...; end'
# CHECKERR: {{.*}}: Unknown command: '{ echo; echo }''{ ... }' is not supported for grouping commands. Please use 'begin; ...; end'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also a regression. these lines shouldn't be joined.

$fish -C 'function fish_command_not_found; echo cmd-not-found; end' -ic "nonexistent-command-1234 1 2 3 4"
#CHECKERR: cmd-not-found
#CHECKERR: fish:
$fish -C 'function fish_command_not_found; echo cmd-not-found; end' -c "nonexistent-command-1234 1 2 3 4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

} else {
// Redirect to stderr _if there's no handler_
io.append_from_specs({redirection_spec_t{STDOUT_FILENO, redirection_mode_t::fd, L"2"}},
L"");
// If we have no handler, just print it as a normal error.
error = _(L"Unknown command:");
if (!event_args.empty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a newline (after the if which github won't allow me to mark):

error.push_back(L'\n');

I believe that's a pre-existing bug that this just happens to run into.

@@ -13,6 +13,7 @@ end

function __fish_default_command_not_found_handler
printf (_ "fish: Unknown command: %s\n") (string escape -- $argv[1]) >&2
return 127
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other handlers should also default to return 127.

@faho
Copy link
Member

faho commented Mar 28, 2023

Alright, closing this since there are open issues and it's conflicting.

If you get back to it we can of course reopen (or you can file a new PR).

@faho faho closed this Mar 28, 2023
@zanchey zanchey added this to the will-not-implement milestone May 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fish command not found magic gives exit code 127
3 participants