oppiliappan / statix

lints and suggestions for the nix programming language
https://git.peppe.rs/languages/statix/about
MIT License
552 stars 21 forks source link

Crash when passing empty string in stdin #78

Open ipvych opened 1 year ago

ipvych commented 1 year ago

Steps to reproduce:

echo "" | RUST_BACKTRACE=full statix check -s

Results in

[E00] Error: Syntax error
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /build/statix-0.5.6-vendor.tar.gz/ariadne/src/source.rs:109:25
stack backtrace:
   0:     0x55be76e9309c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf2ea00d5f3b53d9f
   1:     0x55be76ec4c1e - core::fmt::write::ha076a7e65c6b1874
   2:     0x55be76ea51e1 - std::io::Write::write_fmt::h9630bb3b0fe886f5
   3:     0x55be76ead0b5 - std::panicking::default_hook::{{closure}}::h64163197f96398c1
   4:     0x55be76eacd12 - std::panicking::default_hook::h92625161492e6b48
   5:     0x55be76ead5d1 - std::panicking::rust_panic_with_hook::hfdd7d6bb6788c6c2
   6:     0x55be76e933d7 - std::panicking::begin_panic_handler::{{closure}}::he81a60a7ef84ad4a
   7:     0x55be76e931b4 - std::sys_common::backtrace::__rust_end_short_backtrace::h62801bf9780239e6
   8:     0x55be76ead282 - rust_begin_unwind
   9:     0x55be76d07cc3 - core::panicking::panic_fmt::hfd221b9f37504b4a
  10:     0x55be76d07c02 - core::panicking::panic_bounds_check::hd62ce49e2c7e15d6
  11:     0x55be76d6ba3c - ariadne::source::Source::get_offset_line::hff6557d6c6989d76
  12:     0x55be76d0fa9d - ariadne::write::<impl ariadne::Report<S>>::write::h6d21c3b3fc711aae
  13:     0x55be76d1c0bd - statix::traits::write_stderr::hf326e6e9162805f2
  14:     0x55be76d366e0 - statix::lint::main::main::h02d93095411c466b
  15:     0x55be76d0b3b1 - statix::main::h75b6529e2c6a3a28
  16:     0x55be76d09243 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd0a11a681f67d665
  17:     0x55be76d09d29 - std::rt::lang_start::{{closure}}::h4151b7edf354832b
  18:     0x55be76e9e6b5 - std::rt::lang_start_internal::h09bcc9fffd987f14
  19:     0x55be76d0b5c2 - main
  20:     0x7f184c42924e - __libc_start_call_main
  21:     0x7f184c429309 - __libc_start_main_alias_1
  22:     0x55be76d07f05 - _start
  23:                0x0 - <unknown>

Expected result: Should return

[E00] Error: Syntax error
   ╭─[<stdin>:1:1]
   │
 1 │
   · │
   · ╰─ Unexpected end of file
───╯

as passing empty file would.

Additional context: Providing empty empty file as input (not stdin) works, stdin with a single space character works as well.

Output of statix --version:

statix 0.5.6