Skip to content

make hook lists still return a value - #19597

Merged
fdncred merged 4 commits into
nushell:mainfrom
pheenty:hooks
Nov 18, 2026
Merged

fdncred merged 4 commits into
nushell:mainfrom
pheenty:hooks

Conversation

@pheenty

@pheenty pheenty commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Title (issue #19596 - check related discussion).
Really this is only applicable for command not found.
Also, while I was at, removed some vecs being passed around and cloned in nu-cmd-base::hook, where slices are enough.

User-facing changes (Release notes)

You can now have a list of closures still modify the returned error message of command not found, it takes the first non-empty return value.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review overview

🟡 Changes recommended

A list hook now returns its result, so the null | append {closure} hook from the issue sets the help text on the branch, and so do string hooks and nested lists. Left to fix: a hook that ends in an external command hides a later hook's string, a record hook with a closure code still returns nothing, and there's no test.

Findings: 0 High severity · 3 Medium severity · 2 Low severity

Open (5)

Notes from my clanker, checked on 43e55a8. Built the branch and ran each case on it and on 0.117.1 (651f0e4). Tried the loop from the first thread as a patch on the branch, and ran the suggested test on the unpatched head (2 passed). CI is green on this head (clippy and tests on Linux, macOS and Windows), so I didn't rerun those locally.

Comment thread crates/nu-cmd-base/src/hook.rs Resolved
Comment thread crates/nu-cmd-base/src/hook.rs Resolved
&mut stack,
None,
vec![("cmd_name".into(), Value::string(name, span))],
&[("cmd_name".into(), Value::string(name, span))],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Low severity doc_config.nu still says closure or null

crates/nu-config/default_files/doc_config.nu still documents hooks.command_not_found (closure|null). If lists are meant to work now, that line should say so, and say that the first hook to return a value sets the help text.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh so that's what you even meant.
because it RAN with the list, but didn't change the error message. ok will change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

which hook in the list sets the help text?

Comment thread crates/nu-cmd-base/src/hook.rs Resolved
Comment thread crates/nu-cmd-base/src/hook.rs Resolved
@pheenty
pheenty requested a review from fdncred November 18, 2026 19:28
@fdncred

fdncred commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What are your thoughts on this?

Non-empty instead of non-null: the filter is now !v.is_empty(), so a first hook that returns '' or [] now loses to a later string. The PR body still says "first non-null return value". An int that comes first still wins.

@pheenty

pheenty commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

I don't see why would you want an empty help message. Changed release notes.

@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Nov 18, 2026
@fdncred
fdncred merged commit 16817a8 into nushell:main Nov 18, 2026
14 checks passed
@fdncred

fdncred commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 18, 2026
@pheenty
pheenty deleted the hooks branch November 18, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants