Repository navigation
Closed
Labels
A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)A:error-unhelpfulThe error message you observe is not helpful to identify the problemcategory:bugSomething isn't working
Milestone
Description
Describe the bug
When creating an error using the spans of $in or $it inside a block, the arrow points at the whole block. Below is a collection of examples that show the wrong spans:
How to reproduce
Example 1
> def shl [] {
let inp = $in
if true {
let span = (metadata $inp).span # Defining the span here gives wrong output
error make {
msg: "Error",
label: {
text: "error",
start: $span.start,
end: $span.end
}
}
}
}
> 2 | shl
Error:
× Error
╭─[entry #89:2:1]
2 │ let inp = $in
3 │ ╭─▶ if $true {
4 │ │ let span = (metadata $inp).span
5 │ │ error make {
6 │ │ msg: "Error",
7 │ │ label: {
8 │ │ text: "error",
9 │ │ start: $span.start,
10 │ │ end: $span.end
11 │ │ }
12 │ │ }
13 │ ├─▶ }
· ╰──── error
14 │ }
╰────
> def shl [] {
let inp = $in
let span = (metadata $inp).span # Defining the span here results in correct span
if true {
error make {
msg: "Error",
label: {
text: "error",
start: $span.start,
end: $span.end
}
}
}
}
> 2 | shl
Error:
× Error
╭─[entry #91:1:1]
1 │ def shl [] {
2 │ let inp = $in
· ─┬─
· ╰── error
3 │ let span = (metadata $inp).span
╰────
Example 2
> def "test bits" [] {
0..4 | each {|it|
if true {
let span = (metadata $it).span # This will show the wrong span
error make {
msg: "Test mismatch",
label: {
text: $"error"
start: $span.start
end: $span.end
}
}
}
}
}
> test bits
Error:
× Test mismatch
╭─[entry #4:2:1]
2 │ 0..4 | each {
3 │ ╭─▶ if $true {
4 │ │ let span = (metadata $it).span # This will show the wrong span
5 │ │ error make {
6 │ │ msg: "Test mismatch",
7 │ │ label: {
8 │ │ text: $"error"
9 │ │ start: $span.start
10 │ │ end: $span.end
11 │ │ }
12 │ │ }
13 │ ├─▶ }
· ╰──── error
14 │ }
╰────
> def "test bits" [] {
0..4 | each {|it|
let span = (metadata $it).span # This will show a better span
if true {
error make {
msg: "Test mismatch",
label: {
text: $"error"
start: $span.start
end: $span.end
}
}
}
}
}
> test bits
Error:
× Test mismatch
╭─[entry #6:1:1]
1 │ def "test bits" [] {
2 │ 0..4 | each {
· ┬
· ╰── error
3 │ let span = (metadata $it).span
╰────
Expected behavior
Ideally, the true span of $it, or $inp would be shown and would not depend on where the $span variable is defined.
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.59.0 |
| branch | main |
| short_commit | 1fd7b9a |
| commit_hash | 1fd7b9a |
| commit_date | 2022-02-12 11:11:54 +00:00 |
| build_os | linux-x86_64 |
| rust_version | rustc 1.58.1 (db9d1b20b 2022-01-20) |
| rust_channel | stable-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.58.0 (f01b232bc 2022-01-19) |
| pkg_version | 0.59.0 |
| build_time | 2022-02-12 14:03:38 +02:00 |
| build_rust_channel | release |
| features | dataframe, default, trash, which, zip |
| installed_plugins | gstat |
Additional context
No response
Metadata
Metadata
Assignees
Labels
A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)A:error-unhelpfulThe error message you observe is not helpful to identify the problemcategory:bugSomething isn't working
Activity
kubouch commentedon May 20, 2022
The issue appeared again in both examples.
sophiajt commentedon Aug 10, 2023
It's a little better now, but not great:
Bahex commentedon Jul 26, 2026
This seems to be partially solved?
error make's labels' structure is now:Rather than:
And it works as expected when the span is in its own record:
But
make errorseemingly accepts the older structure as well, but it always points to thelabelfield because that label record is invalid and should raise an error. However it doesn't appear as its own distinct error and leads to confusion.feat(error make)!: raise errors for invalid labels (nushell#18755)