Skip to content

FEATURE: write better errors for error make and complete the doc#8511

Merged
fdncred merged 10 commits intonushell:mainfrom
amtoine:feature/error-make/better-errors
Mar 22, 2023
Merged

FEATURE: write better errors for error make and complete the doc#8511
fdncred merged 10 commits intonushell:mainfrom
amtoine:feature/error-make/better-errors

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Mar 18, 2023

Description

this PR

  • refactors ErrorMake::run to avoid duplicate branches depending on the value of --unspanned
  • completes the examples
    1. show a really simple error make call, without any command definition
    2. show a complete error format with all possible fields
    3. the command definition but with indentation and slightly better description
  • adds results to the first two examples
  • gives meaningful error messages for all known "bad" error formats, using the span of the error format or the span of $format.label to better explain why the format is bad

User-Facing Changes

users have now the following help

Examples:
  Create a simple custom error
  > error make {msg: "my custom error message"}

  Create a more complex custom error
  > error make {
        msg: "my custom error message"
        label: {
            text: "my custom label text"  # not mandatory unless $.label exists
            start: 123  # not mandatory unless $.label.end is set
            end: 456  # not mandatory unless $.label.start is set
        }
    }

  Create a custom error for a custom command that shows the span of the argument
  > def foo [x] {
        let span = (metadata $x).span;
        error make {
            msg: "this is fishy"
            label: {
                text: "fish right here"
                start: $span.start
                end: $span.end
            }
        }
    }

and the following error messages when the error format is bad https://asciinema.org/a/568107 🥳

Tests + Formatting

  • 🟢 cargo fmt --all
  • 🟢 cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect
  • 🔴 cargo test --workspace
    => the tests do not pass but they do not pass on latest main either => i should cargo clean, but that's an expensive operation on my machine...

After Submitting

the documentation would have to be regenerated over on the website

amtoine added 10 commits March 17, 2023 20:18
This commit avoids duplicate code between the two branches of
`error make` depending on the value of `--unspanned`.
- when `$.label` is set but not `$.label.text`
- when `$.label.start` is set but not `$.label.end`
- when `$.label.end` is set but not `$.label.start`
- when `$.msg` is not set
This commit allows to narrow down the "format error" span to the
minimal part of the format record to help the user the most.
This commit aims at regrouping all the error format matches, to
the bottom, for easier readability and avoid mixing these errors
with the actual working branches.
This commit makes clippy happy.
- the first one is just a simple `error make` call, without any
command definition
- the second one calls the command defined with a fishy argument
This call does not bring anything as the "ShellError" results do
not print anything.
These are the "simple" examples that do not require commands or
more complex structures.
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 18, 2023

even with a cargo clean and a reboot to free all volatile memore in my machine, it does fail locally 😕 🤷

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2023

Codecov Report

Merging #8511 (c42f836) into main (8543b07) will decrease coverage by 0.38%.
The diff coverage is 84.48%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8511      +/-   ##
==========================================
- Coverage   68.52%   68.14%   -0.38%     
==========================================
  Files         621      622       +1     
  Lines      100124   100589     +465     
==========================================
- Hits        68608    68548      -60     
- Misses      31516    32041     +525     
Impacted Files Coverage Δ
crates/nu-parser/src/errors.rs 6.57% <0.00%> (-0.09%) ⬇️
crates/nu-protocol/src/value/stream.rs 80.00% <35.29%> (-5.14%) ⬇️
crates/nu-cmd-lang/src/core_commands/error_make.rs 65.47% <56.62%> (-3.22%) ⬇️
crates/nu-parser/src/parser.rs 83.30% <84.00%> (-0.34%) ⬇️
crates/nu-protocol/src/pipeline_data.rs 76.19% <85.71%> (+0.22%) ⬆️
crates/nu-command/src/filters/join.rs 93.17% <93.17%> (ø)
crates/nu-cmd-lang/src/core_commands/do_.rs 94.98% <100.00%> (+0.07%) ⬆️
crates/nu-cmd-lang/src/core_commands/try_.rs 94.78% <100.00%> (+0.13%) ⬆️
crates/nu-command/src/debug/timeit.rs 99.09% <100.00%> (-0.91%) ⬇️
crates/nu-command/src/default_context.rs 99.78% <100.00%> (+<0.01%) ⬆️
... and 5 more

... and 10 files with indirect coverage changes

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 18, 2023

well glad it passes in the CI 😌 👀

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Mar 22, 2023

thanks

@fdncred fdncred merged commit 626410b into nushell:main Mar 22, 2023
@amtoine amtoine deleted the feature/error-make/better-errors branch March 22, 2023 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants