Skip to content

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

@amtoine

Description

@amtoine

Describe the bug

ok so i was throwing some errors, used a start bigger than the end in the lable of the error make format record and the session crashed 😬

Error:
  Γ— msg
   ╭─[Host Environment Variables:1:1]
 1 β”‚ "ALACRITTY_LOG"="/tmp/Alacritty-29591.log"
   Β· thread 'main' panicked at 'assertion failed: line_range.contains(&offset)', /home/disc/a.stevan/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/miette-5.6.0/src/handlers/graphical.rs:622:9
stack backtrace:
   0:     0x55e65ef162e5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3155a8c966b4beb5
   1:     0x55e65d97f75e - core::fmt::write::h062c617411b691df
   2:     0x55e65ef0e955 - std::io::Write::write_fmt::hb61fdf1275c61e1c
   3:     0x55e65ef160b5 - std::sys_common::backtrace::print::hca896ae22beb06cb
   4:     0x55e65ef17e3f - std::panicking::default_hook::{{closure}}::h0b5eeed5cf36ab5f
   5:     0x55e65ef17baa - std::panicking::default_hook::h8932b573145a321b
   6:     0x55e65ef184d0 - std::panicking::rust_panic_with_hook::h4b1447a24e3e94f8
   7:     0x55e65ef18234 - std::panicking::begin_panic_handler::{{closure}}::h8701da9995a3820c
   8:     0x55e65ef167fc - std::sys_common::backtrace::__rust_end_short_backtrace::hb696c5ed02a01598
   9:     0x55e65ef17fb2 - rust_begin_unwind
  10:     0x55e65d5d4b23 - core::panicking::panic_fmt::h8aa706a976963c88
  11:     0x55e65d5d4bfd - core::panicking::panic::h622b2a38bce78ff3
  12:     0x55e65da06f0e - miette::handlers::graphical::GraphicalReportHandler::visual_offset::h8fc7320eab301409
  13:     0x55e65da11723 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h2f29c1b450b6c253
  14:     0x55e65da0d24c - <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::hd9436afc38be2b2f
  15:     0x55e65da0ba96 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::haab69343290479e7
  16:     0x55e65da071b2 - miette::handlers::graphical::GraphicalReportHandler::render_single_line_highlights::h9c29feedd35f4878
  17:     0x55e65da056e7 - miette::handlers::graphical::GraphicalReportHandler::render_context::ha00fe8a1c3baf649
  18:     0x55e65da04c81 - miette::handlers::graphical::GraphicalReportHandler::render_snippets::h33b7db3353cfb6d8
  19:     0x55e65da02a49 - miette::handlers::graphical::GraphicalReportHandler::render_report::h645a2489b1fea71f
  20:     0x55e65e3ebc43 - <nu_protocol::cli_error::CliError as core::fmt::Debug>::fmt::hc759b907cd98a05b
  21:     0x55e65d97f75e - core::fmt::write::h062c617411b691df
  22:     0x55e65ef0d6e2 - <&std::io::stdio::Stderr as std::io::Write>::write_fmt::hb6d8fd1d70951441
  23:     0x55e65ef0dedb - std::io::stdio::_eprint::hf91a18d9ef30cd2e
  24:     0x55e65da72d48 - nu_cli::util::eval_source::h0e15e2886652bd5c
  25:     0x55e65da845bf - nu_cli::repl::evaluate_repl::h571d445a1d1333f9
  26:     0x55e65da421b5 - nu::run::run_repl::h743ba7411fe55448
  27:     0x55e65da4fa56 - nu::main::hb802d4352f579560
  28:     0x55e65da508cc - std::sys_common::backtrace::__rust_begin_short_backtrace::hf2a1d2df25c3671d
  29:     0x55e65da508d7 - std::rt::lang_start::{{closure}}::h346508c00f557365
  30:     0x55e65ef0691b - std::rt::lang_start_internal::hcd7e45acd25ab5ab
  31:     0x55e65da50095 - main
  32:     0x7fcc2b829d90 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  33:     0x7fcc2b829e40 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:392:3
  34:     0x55e65d637745 - _start
  35:                0x0 - <unknown>

How to reproduce

run something like

error make {msg: "msg", label: {text: "text" start: 100 end: 20}}

and the same goes with

error make {
    msg: "msg"
    label: {
        text: "text"
        start: ($nu.scope.engine_state.source_bytes - 20)
        end: ($nu.scope.engine_state.source_bytes - 100)
    }
}

it appears the start must be somewhat enough bigger that the end πŸ€”
it they are too close, you just get an empty span.

for instance, if they are only 10 apart, start still bigger than end, we get

>_ error make {
:::     msg: "msg"
:::     label: {
:::         text: "text"
:::         start: ($nu.scope.engine_state.source_bytes - 90)
:::         end: ($nu.scope.engine_state.source_bytes - 100)
:::     }
::: }
Error:
  Γ— msg
   ╭─[entry #6:4:1]
 4 β”‚         text: "text"
 5 β”‚         start: ($nu.scope.engine_state.source_bytes - 90)
   Β·                                 ┬
   Β·                                 ╰── text
 6 β”‚         end: ($nu.scope.engine_state.source_bytes - 100)
   ╰────

Expected behavior

i think using a start stricly bigger than the end should give a clear error πŸ‘

Screenshots

No response

Configuration

key value
version 0.77.2
branch main
commit_hash d1309a3
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
build_time 2023-03-20 09:27:57 +01:00
build_rust_channel release
features default, zip
installed_plugins gstat, len, query, query json, query web, query xml

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)category:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions