Standardise the use of ShellError::UnsupportedInput and ShellError::TypeMismatch and add spans to every instance of the former#7217
Conversation
|
Good stuff! My only concern is that we also have places where If I understand your change correctly the additional variant you added is for indicating the only valid types. Maybe we should also split up EDIT: Totallly missed that we kind of already have a variant for a input type error: |
Hmm… maybe I should change my new UnsupportedInput uses to use that… actually, it's so similar to what I've edited UnsupportedInput to, that maybe I'll convert all PipelineMismatch uses to UnsupportedInput, then rename it in entirety to PipelineMismatch (i.e. eliminate UnsupportedInput due to both its cases being covered by -Mismatch variants)… Then again, you are right that people seem to "like" the name UnsupportedInput more… |
|
We still need a variant to signal that the type was fine but the values in the input won't work with the command. |
4c6e1fe to
4e95807
Compare
|
OK, so… in the end I just used a bunch of Also, I added Regarding It now passes all the tests, so it's where I want it to be. |
|
Nice, thanks @webbedspace! This looks like a big improvement to our error messages. I will take a closer look at this tomorrow but I don't expect any issues. Once the remaining conflicts are fixed, should be able to merge this after the v0.73 release (which is happening tomorrow). |
ee8539a to
b0b2243
Compare
|
Random question, but why does the CI run nu-fmt-clippy on three platforms? Isn't that just a code style test? |
IIRC Thanks for all the meticulous work on this PR! |
5563db0 to
247311d
Compare
* Change various .span().expect() into a special .expect_span() call. * Correct histogram error to CantFindColumn * Fix places where PipelineData::Empty wasn't matched
|
I changed the "bunch of |
rgwood
left a comment
There was a problem hiding this comment.
This PR took a very long time to read through, so I can only imagine how much work it was to implement.
Incredible work, @webbedspace - this is a big step forward for Nu's errors. Thank you!
I've left a few small comments but I don't think they should hold up merging this. I think it's ready to go.
| // Propagate existing errors | ||
| input.clone() |
There was a problem hiding this comment.
I'm a little iffy on this assumption that no span will always mean an error - feels like the kind of thing that might cause trouble in the future. Not a big enough deal to be a blocker though.
| head: Span, | ||
| ) -> Result<PipelineData, ShellError> { | ||
| let (value, metadata) = input.collect_string_strict(head)?; | ||
| let (value, _span, metadata, ..) = input.collect_string_strict(head)?; |
There was a problem hiding this comment.
Don't think this .. is needed?
| None => input.map(move |v| cmd(&v, &arg, v.span().unwrap_or(span)), ctrlc), | ||
| None => input.map( | ||
| move |v| { | ||
| match v { | ||
| // Propagate errors inside the input | ||
| Value::Error { .. } => v, | ||
| _ => cmd(&v, &arg, span), | ||
| } | ||
| }, | ||
| ctrlc, | ||
| ), |
There was a problem hiding this comment.
I don't have any reason to believe that this will cause problems, but it's an interesting change that affects a lot of commands. Something to take a look at if anything breaks unexpectedly.
Description
I thus devised the following standard: input type-checking only uses UnsupportedInput, and argument type-checking only uses TypeMismatch. Moreover, to differentiate them, UnsupportedInput now has two error arrows (spans), one pointing at the command and the other at the input origin, while TypeMismatch only has the one (because the command should always be nearby)
matchsites which take a Value::Error, then throw it away and replace it with a new Value::Error with less/misleading information (such as reporting the error as an "incorrect type"). I believe that the earliest errors are the most important, and should always be propagated where possible.<type>, got<type>", I created OnlySupportsThisInputType as a variant of it.call.headwas given for both - were fixed to use different spans.Example
BEFORE
AFTER
User-Facing Changes
Various error messages suddenly make more sense (i.e. have two arrows instead of one).
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 -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspaceto check that all tests passAfter Submitting
If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.