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.
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:
https:/ /github. com/zsh- users/zsh/ blob/9e2afb9298 7d7fd96a838c15b 6641cc1b634a825 /README# L207-L214
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.