FIX: correct bad span in std help errors#9039
Merged
amtoine merged 5 commits intonushell:mainfrom May 12, 2023
Merged
Conversation
it's not called `module_not_found_error`...
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #9039 +/- ##
==========================================
- Coverage 68.90% 68.71% -0.19%
==========================================
Files 641 640 -1
Lines 102337 101681 -656
==========================================
- Hits 70516 69875 -641
+ Misses 31821 31806 -15 |
3 tasks
Member
Author
|
solving the conflicts... ♻️ |
This should solve the merge conflicts.
std help errorsstd help errors
This avoids seeing `[foo, bar, baz]` when running ``` std help foo bar baz ``` This commit makes it `foo bar baz`.
Member
Author
|
adding an idea from #9101 the only thing is that i still get an incorrect span 🤔 > std help commands foo bar
Help pages from external command foo bar:
No manual entry for foo bar
Error:
× std::help::command_not_found
╭─[entry #1:1:1]
1 │ std help commands foo bar
· ─┬─
· ╰── command not found
╰────i tried to apply diff --git a/crates/nu-std/lib/help.nu b/crates/nu-std/lib/help.nu
index b33594ee7..cb6ee144b 100644
--- a/crates/nu-std/lib/help.nu
+++ b/crates/nu-std/lib/help.nu
@@ -672,7 +672,10 @@ export def "help commands" [
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)
+ command-not-found-error {
+ start: (metadata ($command | get 0) | get span.start)
+ end: (metadata ($command | last 1 |get 0) | get span.end)
+ }
}
}but i get the following now 🤔 |
Contributor
|
I suppose the problem there is `metadata` is called with a pipeline
expression rather than a reference to the original variable. This kind of
syntax works for me:
```
export def foo [...command:string] {
let spans = [(metadata $command.0).span.start (metadata
$command.1).span.end]
error make { msg:foo label:{ text:bar start:$spans.0 end:$spans.1 } }
〉t foo bar bas
Error:
× foo
╭─[entry #98:1:1]
1 │ t foo bar bas
· ───┬───
· ╰── bar
╰────
```
... but of course only for exactly 2 words in the parameter list. I don't
see a way to generalise to N words, the `$command.1` form cannot be
generalized to `$command.$var` and you've already demonstrated that
`metadata ($command | get $var)` won't work
It is unexpected that `(metadata $command)` doesn't get the span of the
whole argument, since the parameter obviously does get the entire value.
I could see some user confusion arising from this glitch -- user might
think the problem was some misspelling of just the first word.
But doing something about it will require parser expertise from the core
team, I think.
…On Fri, May 5, 2023 at 12:27 PM Antoine Stevan ***@***.***> wrote:
adding an idea from #9101 <#9101>
cc/ @bobhy <https://github.com/bobhy>
the only thing is that i still get an incorrect span 🤔
> std help commands foo barHelp pages from external command foo bar:No manual entry for foo barError:
× std::help::command_not_found
╭─[entry #1:1:1]
1 │ std help commands foo bar
· ─┬─
· ╰── command not found
╰────
i tried to apply
diff --git a/crates/nu-std/lib/help.nu b/crates/nu-std/lib/help.nu
index b33594ee7..cb6ee144b 100644--- a/crates/nu-std/lib/help.nu+++ b/crates/nu-std/lib/help.nu@@ -672,7 +672,10 @@ export def "help commands" [
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)+ command-not-found-error {+ start: (metadata ($command | get 0) | get span.start)+ end: (metadata ($command | last 1 |get 0) | get span.end)+ }
}
}
but i get the following now 🤔
Error:
× std::help::command_not_found
╭─[help:675:1]
675 │ command-not-found-error {
676 │ ╭─▶ start: (metadata ($command | get 0) | get span.start)
677 │ ├─▶ end: (metadata ($command | last 1 |get 0) | get span.end)
· ╰──── command not found
678 │ }
╰────
—
Reply to this email directly, view it on GitHub
<#9039 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPBIZCOJLQHDO6IHXHHIVTXEUS7BANCNFSM6AAAAAAXPM7CPU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
fdncred
pushed a commit
that referenced
this pull request
May 8, 2023
) # Description an example should show what happens quite clearly 😋 > **Note** > the ugly spanned errors you'll see below are fixed in #9039 😌 in all cases we get ``` > std help commands does-not-exist-anywhere Help pages from external command does-not-exist-anywhere: No manual entry for does-not-exist-anywhere Error: × std::help::command_not_found ╭─[help:662:1] 662 │ 663 │ let command = ($command | str join " ") · ─┬─ · ╰── command not found 664 │ ╰──── ``` but ## ❌ before this PR ``` > std help does-not-exist-anywhere Help pages from external command does-not-exist-anywhere: No manual entry for does-not-exist-anywhere ``` without any error, which makes it inconsistent with all the other `std help` commands which give errors when not finding an item 🤔 ## ✔️ with this PR ``` > std help does-not-exist-anywhere Help pages from external command does-not-exist-anywhere: No manual entry for does-not-exist-anywhere Error: × std::help::item_not_found ╭─[help:740:1] 740 │ 741 │ let item = ($item | str join " ") · ─┬─ · ╰── item not found 742 │ ╰──── ``` # User-Facing Changes more consistent errors when using `std help` and `std help commands`, as shown above. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting ``` $nothing ```
This commit should fix the merge conflicts in !9039.
amtoine
added a commit
that referenced
this pull request
May 12, 2023
related to - #9101 - #9039 # Description i actually forgot to fix in #9039 the new "*item*" introduced by #9101... 👀 there it is 😇 # User-facing changes going from ``` > std help git-commiteuwqi Help pages from external command git-commiteuwqi: No manual entry for git-commiteuwqi Error: × std::help::item_not_found ╭─[help:721:1] 721 │ 722 │ let item = ($item | str join " ") · ─┬─ · ╰── item not found 723 │ ╰──── ``` to ``` > std help git-commiteuwqi Help pages from external command git-commiteuwqi: No manual entry for git-commiteuwqi Error: × std::help::item_not_found ╭─[entry #2:1:1] 1 │ std help git-commiteuwqi · ───────┬─────── · ╰── item not found ╰──── ``` # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - ⚫ `toolkit test` - ⚫ `toolkit test stdlib` # After Submitting ``` $nothing ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
❌ before this PR
✔️ after this PR
User-Facing Changes
fixes the errors to have proper messages
Tests + Formatting
toolkit fmttoolkit clippytoolkit testtoolkit test stdlibAfter Submitting