Skip to content

FIX: do not allow *start > end* in error make spans#8570

Merged
sholderbach merged 6 commits intonushell:mainfrom
amtoine:fix/error-span/do-not-allow-start-bigger-than-end
Mar 23, 2023
Merged

FIX: do not allow *start > end* in error make spans#8570
sholderbach merged 6 commits intonushell:mainfrom
amtoine:fix/error-span/do-not-allow-start-bigger-than-end

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Mar 22, 2023

This should close #8567.

Description

this PR throws an error when start > end in the most complete branch of ErrorMake::run, i.e. when $.msg, $.label.text, $.label.start and $.label.end are defined.

i've also added a error_start_bigger_than_end_should_fail test to check that it does indeed return the right error.

User-Facing Changes

no more crash when manipulating span bounds and a clear error, e.g.

>_ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}}
Error:
  × invalid error format.
   ╭─[entry #3:1:1]
 1 │ error make {msg: "msg" label: {text: "text" start: 1010 end: 1000}}
   ·                               ──────────────────┬─────────────────
   ·                                                 ╰── `$.label.start` is stricly bigger than `$.label.end`
   ╰────
  help: 1010 > 1000

or

>_ error make {
:::     msg: "msg"
:::     label: {
:::         text: "text"
:::         start: ($nu.scope.engine_state.source_bytes - 90)
:::         end: ($nu.scope.engine_state.source_bytes - 100)
:::     }
::: }
Error:
  × invalid error format.
   ╭─[entry #4:2:1]
 2 │         msg: "msg"
 3 │ ╭─▶     label: {
 4 │ │           text: "text"
 5 │ │           start: ($nu.scope.engine_state.source_bytes - 90)
 6 │ │           end: ($nu.scope.engine_state.source_bytes - 100)
 7 │ ├─▶     }
   · ╰──── `$.label.start` is stricly bigger than `$.label.end`
 8 │     }
   ╰────
  help: 204525 > 204515

Tests + Formatting

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🔴 toolkit test

After Submitting

$nothing

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that is a good one! Thanks. still traumatized from span errors....

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 22, 2023

i just have these failures with toolkit test which look unrelated to this right? 🤔

i've tried merging into latest main but it did not solve the tests 👀

failures:

---- modules::module_import_env_2 stdout ----
=== stderr
Error: nu::shell::file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; $env.FOO
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_2' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:341:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- modules::module_import_env_1 stdout ----
=== stderr
Error: nu::shell::file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env main.nu; use main.nu foo; foo
   ·            ───┬───
   ·               ╰── file not found
   ╰────


thread 'modules::module_import_env_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"foo"`', tests/modules/mod.rs:316:9

---- overlays::overlay_use_dont_cd_overlay stdout ----
=== stderr
Error: nu::shell::file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env test1/test2/spam.nu; $env.PWD | path basename
   ·            ─────────┬─────────
   ·                     ╰── file not found
   ╰────


thread 'overlays::overlay_use_dont_cd_overlay' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"overlay_use_dont_cd_overlay"`', tests/overlays/mod.rs:946:9

---- overlays::overlay_use_do_cd_file_relative stdout ----
=== stderr

thread 'overlays::overlay_use_do_cd_file_relative' panicked at 'assertion failed: `(left == right)`
  left: `"nu-utils"`,
 right: `"test1"`', tests/overlays/mod.rs:919:9

---- parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1 stdout ----
=== stderr
Error: nu::shell::file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol.nu; $env.FOO
   ·            ─────┬────
   ·                 ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"good"`', tests/parsing/mod.rs:177:9

---- parsing::parse_file_relative_to_parsed_file_simple stdout ----
=== stderr
Error: nu::shell::file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ source-env lol/lol/lol.nu; $env.LOL
   ·            ───────┬──────
   ·                   ╰── file not found
   ╰────


thread 'parsing::parse_file_relative_to_parsed_file_simple' panicked at 'assertion failed: `(left == right)`
  left: `""`,
 right: `"lol"`', tests/parsing/mod.rs:99:9


failures:
    modules::module_import_env_1
    modules::module_import_env_2
    overlays::overlay_use_do_cd_file_relative
    overlays::overlay_use_dont_cd_overlay
    parsing::parse_file_relative_to_parsed_file_dont_use_cwd_1
    parsing::parse_file_relative_to_parsed_file_simple

test result: FAILED. 386 passed; 6 failed; 20 ignored; 0 measured; 0 filtered out; finished in 5.01s

error: test failed, to rerun pass `-p nu --test main`

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 22, 2023

Wow that is a good one!

do not ask me how i come to this crash, i have no idea myself 😆

Thanks.

my pleasure 😌

still traumatized from span errors....

i love them and i want them as pretty and reliable as possible 😏

This commit should make the CI typo check happy.
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 22, 2023

i learn how to spell words in d501451 👀

@amtoine amtoine closed this Mar 22, 2023
@amtoine amtoine reopened this Mar 22, 2023
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 22, 2023

ok that is unfortunate 😬

@amtoine amtoine changed the title Fix/error span/do not allow start bigger than end FIX: do not allow *start > end* in error make spans Mar 22, 2023
Some(ShellError::GenericError(
"invalid error format.".into(),
"`$.label.start` is stricly bigger than `$.label.end`".into(),
"`$.label.start` is strictly bigger than `$.label.end`".into(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rephrase it in terms of how it shold be but that is a stylistic choice

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh gotcha 👌

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed it in 806158f 😉

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2023

Codecov Report

Merging #8570 (5b79a96) into main (626410b) will increase coverage by 0.37%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8570      +/-   ##
==========================================
+ Coverage   68.14%   68.51%   +0.37%     
==========================================
  Files         624      624              
  Lines      100678   100681       +3     
==========================================
+ Hits        68606    68985     +379     
+ Misses      32072    31696     -376     
Impacted Files Coverage Δ
crates/nu-cmd-lang/src/core_commands/error_make.rs 62.14% <0.00%> (-3.33%) ⬇️

... and 14 files with indirect coverage changes

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Mar 23, 2023

@amtoine if you can fix the type-o, we can probably land this. Thanks!

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 23, 2023

@amtoine if you can fix the type-o, we can probably land this. Thanks!

i do not understand 😕
i fixed it in d501451 🤔

ok sorry, i forgot about the test 👀
fixed in 5b79a96 😌

@sholderbach
Copy link
Copy Markdown
Member

Merci beaucoup!

@sholderbach sholderbach merged commit 05ff7a9 into nushell:main Mar 23, 2023
@amtoine amtoine deleted the fix/error-span/do-not-allow-start-bigger-than-end branch March 24, 2023 13:07
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 24, 2023

Merci beaucoup!

avec plaisir!

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.

panick when $.label.start is bigger than $.label.end in an error make format record

3 participants