zesterer / ariadne

A fancy diagnostics & error reporting crate
https://crates.io/crates/ariadne
MIT License
1.79k stars 78 forks source link

Ariadne crashes when input is empty #92

Closed 01mf02 closed 1 year ago

01mf02 commented 1 year ago

I am using ariadne inside jaq, in particular here. When supplying jaq with an empty input (see https://github.com/01mf02/jaq/issues/4), it gives the following output:

Error: Unexpected end of input, expected ", -, def, ., try, {, if, .., [, (
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/[...]/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ariadne-0.3.0/src/source.rs:140:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

In the current Git version of ariadne, this is here: https://github.com/zesterer/ariadne/blob/b2d478b2b3a5fe3f14ce9cfab165be1b0fe5934a/src/source.rs#L159

Would it work to use self.lines.get(idx)? instead?

zesterer commented 1 year ago

Yes, self.lines.get(idx) would work. I can try to find time to patch this late this week. Alternatively, I'm happy to accept a PR :)

01mf02 commented 1 year ago

Done. :)

juansc commented 12 months ago

When will this be released? Thanks!

zesterer commented 11 months ago

When will this be released? Thanks!

I've just released 0.4.0, which includes this fix.