From 9ebb61fc2d4047193ec5df36a5f4aff00a184dde Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Fri, 12 May 2023 19:44:39 +0200 Subject: [PATCH] FIX: correct bad span in `std help` errors (#9039) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description ## :x: before this PR ``` >_ std help modules euwioq Error: nu::shell::external_command × External command failed ╭─[help:259:1] 259 │ if ($found_module | is-empty) { 260 │ module_not_found_error (metadata $module | get span) · ──────────────┬────────────── · ╰── Cannot convert record to a string 261 │ } ╰──── help: All arguments to an external command need to be string-compatible ``` ``` >_ std help externs euwioq Error: × std::help::extern_not_found ╭─[help:401:1] 401 │ 402 │ let extern = ($extern | str join " ") · ─┬─ · ╰── extern not found 403 │ ╰──── ``` > **Note** > same kind of error with all the others ## :heavy_check_mark: after this PR ``` > std help modules euwioq 04/28/2023 05:45:50 PM Error: × std::help::module_not_found ╭─[entry #2:1:1] 1 │ std help modules euwioq · ───┬── · ╰── module not found ╰──── ``` ``` > std help externs euwioq 04/28/2023 05:45:53 PM Error: × std::help::extern_not_found ╭─[entry #3:1:1] 1 │ std help externs euwioq · ───┬── · ╰── extern not found ╰──── ``` > **Note** > same with the others # User-Facing Changes fixes the errors to have proper messages # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting ``` $nothing ``` --- crates/nu-std/lib/help.nu | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/crates/nu-std/lib/help.nu b/crates/nu-std/lib/help.nu index 5dd981daf9..48ca11971e 100644 --- a/crates/nu-std/lib/help.nu +++ b/crates/nu-std/lib/help.nu @@ -243,15 +243,13 @@ export def "help modules" [ ] { let modules = $nu.scope.modules - let module = ($module | str join " ") - if not ($find | is-empty) { $modules | find $find --columns [name usage] } else if not ($module | is-empty) { - let found_module = ($modules | where name == $module) + let found_module = ($modules | where name == ($module | str join " ")) if ($found_module | is-empty) { - module_not_found_error (metadata $module | get span) + module-not-found-error (metadata $module | get span) } show-module ($found_module | get 0) @@ -347,12 +345,10 @@ export def "help aliases" [ ] { let aliases = ($nu.scope.aliases | sort-by name) - let alias = ($alias | str join " ") - if not ($find | is-empty) { $aliases | find $find --columns [name usage] } else if not ($alias | is-empty) { - let found_alias = ($aliases | where name == $alias) + let found_alias = ($aliases | where name == ($alias | str join " ")) if ($found_alias | is-empty) { alias-not-found-error (metadata $alias | get span) @@ -387,12 +383,10 @@ export def "help externs" [ | str trim ) - let extern = ($extern | str join " ") - if not ($find | is-empty) { $externs | find $find --columns [name usage] } else if not ($extern | is-empty) { - let found_extern = ($externs | where name == $extern) + let found_extern = ($externs | where name == ($extern | str join " ")) if ($found_extern | is-empty) { extern-not-found-error (metadata $extern | get span) @@ -453,12 +447,10 @@ export def "help operators" [ ] { let operators = (get-all-operators) - let operator = ($operator | str join " ") - if not ($find | is-empty) { $operators | find $find --columns [type name] } else if not ($operator | is-empty) { - let found_operator = ($operators | where name == $operator) + let found_operator = ($operators | where name == ($operator | str join " ")) if ($found_operator | is-empty) { operator-not-found-error (metadata $operator | get span) @@ -657,18 +649,17 @@ export def "help commands" [ ] { let commands = ($nu.scope.commands | where not is_extern | reject is_extern | sort-by name) - let command = ($command | str join " ") - if not ($find | is-empty) { # TODO: impl find for external commands $commands | find $find --columns [name usage search_terms] | select name category usage signatures search_terms } else if not ($command | is-empty) { - let found_command = ($commands | where name == $command) + let target_command = ($command | str join " ") + let found_command = ($commands | where name == $target_command) if ($found_command | is-empty) { try { - print $"(ansi default_italic)Help pages from external command ($command | pretty-cmd):(ansi reset)" - ^($env.NU_HELPER? | default "man") $command + print $"(ansi default_italic)Help pages from external command ($target_command | pretty-cmd):(ansi reset)" + ^($env.NU_HELPER? | default "man") $target_command } catch { command-not-found-error (metadata $command | get span) }