Using Zsh, it doesn't show an error message when command not found

Bug #1766068 reported by Ricardo Pérez López on 2018-04-22
This bug affects 8 people
Affects Status Importance Assigned to Milestone
command-not-found (Debian)
command-not-found (Ubuntu)

Bug Description

- Using latest Ubuntu Bionic, full updated.

- Using Zsh.

My ~/.zshrc includes the following line:

  . /etc/zsh_command_not_found

When I type (for example):

  $ sdlkfjslkdfjkdslf

it doesn't say nothing. No error message.

If I change the line #11 of /etc/zsh_command_not_found and I remove '--no-failure-msg' option, then it works OK:

  /usr/lib/command-not-found -- ${1+"$1"} && : (line 11, without --no-failure-msg option)

I think the above option should be removed from /etc/zsh_command_not_found.

tags: added: command-not-found zsh
tags: removed: zsh
tags: added: zsh
tags: added: bionic
Ricardo Pérez López (ricardo) wrote :

It works out-of-the-box in Ubuntu Xenial.

Ricardo Pérez López (ricardo) wrote :

I've found the origin of the problem.

Since Zsh 5.3, the command_not_found_handler() behavior has changed, as you can see here:

Copy & paste:

  6) Previously, if the function command_not_found_handler was run
  in place of a command-not-found error, and the function returned
  non-zero status, zsh set the status to 127 and printed an error message
  anyway. Now, the status from the handler is retained and no additional
  message is printed. The main reasons for this change are that it was not
  possible to return a non-zero status to the parent shell from a command
  executed as a replacement, and the new implementation is more consistent
  with other shells.

So now, when you define a custom command_not_found_handler() function in Zsh, the shell never print an error message by itself, i.e., the error message must be printed by the handler function.

According to the above, I think the only solution is by remove the '--no-failure-msg' option from the /etc/zsh_command_not_found and therefore the command_not_found_handler() function is the only responsible to print error messages to the user.

Ricardo Pérez López (ricardo) wrote :

It worked in Ubuntu Xenial because it ships Zsh 5.1 and the new behavior was introduced in Zsh 5.3.

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in command-not-found (Ubuntu):
status: New → Confirmed
Changed in command-not-found (Ubuntu):
importance: Undecided → Low
status: Confirmed → Triaged
Shuhao (shuhao) wrote :

The first line of the handler is also somewhat problematic. Namely:

[[ -x /usr/lib/command-not-found ]] || return 1

If command-not-found package is removed and this file is not, it will stop printing the message even if --no-failure-msg is removed.

Shuhao (shuhao) wrote :

Actually, maybe I spoke too soon: there's an if guarding the definition of the function at the top of that file.

Ricardo Pérez López (ricardo) wrote :

Any news about this issue?

Ricardo Pérez López (ricardo) wrote :

The bug is still reproducible with Ubuntu 19.04.

Joel Cross (ukch) wrote :

I raised the equivalent bug in Debian:

Joel Cross (ukch) wrote :

I have added the above patch to remove the --no-failure-message flag, which seems to fix the problem (I have also bumped compat and standards versions).
Please consider applying the patch and releasing a new version of the package.

The attachment "Remove --no-failure-message from zsh_command_not_found" seems to be a debdiff. The ubuntu-sponsors team has been subscribed to the bug report so that they can review and hopefully sponsor the debdiff. If the attachment isn't a patch, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are member of the ~ubuntu-sponsors, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issue please contact him.]

tags: added: patch
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

affects: command-not-found → ubuntu
Changed in ubuntu:
status: New → Confirmed
no longer affects: ubuntu
Changed in command-not-found (Debian):
status: Unknown → New
Simon Quigley (tsimonq2) wrote :

Please submit this patch to Debian, where it will flow down to Ubuntu.

Unsubscribing the Ubuntu Sponsors Team.

Julian Andres Klode (juliank) wrote :

Simon was a bit wrong, as the upstream situation is reversed, but either way, I guess it's me taking a look at it :)

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.