Skip to content

fix: prevent ariadne from panicking on empty stdin/file#1588

Open
daschinmoy21 wants to merge 4 commits intomolybdenumsoftware:masterfrom
daschinmoy21:fix-empty-stdin-crash-moly
Open

fix: prevent ariadne from panicking on empty stdin/file#1588
daschinmoy21 wants to merge 4 commits intomolybdenumsoftware:masterfrom
daschinmoy21:fix-empty-stdin-crash-moly

Conversation

@daschinmoy21
Copy link
Copy Markdown

Fixes oppiliappan#78

When statix receives an empty string via stdin, an empty Report is generated. Passing an empty string to ariadne's Source::from causes an index out of bounds panic. Supplying a string with a single space as a fallback prevents this panic while keeping the error location at byte offset 0.

Output after this fix-

echo "" | nix run . -- check -s

[E00] Error: Syntax error
╭─[:1:1]

1 │
· │
· ╰─ Unexpected end of file
───╯

@mightyiam
Copy link
Copy Markdown
Member

How about a test for this?

@daschinmoy21
Copy link
Copy Markdown
Author

Yea exactly i actually made a test last night. Will raise a pr in the evening after college ends

@mightyiam mightyiam force-pushed the fix-empty-stdin-crash-moly branch from 0f1a07c to 11230da Compare April 8, 2026 12:45
Comment thread bin/src/traits.rs Outdated
Comment thread bin/tests/_utils.rs Outdated
@daschinmoy21 daschinmoy21 force-pushed the fix-empty-stdin-crash-moly branch from 821c749 to 544dcf8 Compare April 9, 2026 16:57
@daschinmoy21 daschinmoy21 changed the title fix(cli): prevent ariadne from panicking on empty stdin fix: prevent ariadne from panicking on empty stdin Apr 9, 2026
Comment thread bin/tests/_utils.rs Outdated
@daschinmoy21 daschinmoy21 changed the title fix: prevent ariadne from panicking on empty stdin fix: prevent ariadne from panicking on empty stdin/file Apr 10, 2026
@mightyiam
Copy link
Copy Markdown
Member

Some conflicts

@daschinmoy21
Copy link
Copy Markdown
Author

On it

@daschinmoy21 daschinmoy21 force-pushed the fix-empty-stdin-crash-moly branch from 544dcf8 to f8088d2 Compare April 22, 2026 20:35
@daschinmoy21
Copy link
Copy Markdown
Author

Should be good now. handles empty stdin and files now. Now it returns

[E00] Error: Syntax error
   --> <stdin>:1:1
    |
    = Unexpected end of file
[E00] Error: Syntax error
   --> empty_nix_file.nix:1:1
    |
    = Unexpected end of file

Comment thread bin/src/traits.rs
@daschinmoy21
Copy link
Copy Markdown
Author

I checked the lock file and turns out ariadne crate quite outdated. statix is using v0.1.3. latest is 0.6.0 which also fixes the empty stdin panic we are trying to solve. other additional change required would be in traits.rs,change

   CliReport::build(report_kind, src_id, offset)

to

 CliReport::build(report_kind, (src_id, offset..offset))

Post update it now returns

printf "" | cargo run -- check -s
    Finished [`dev` profile [unoptimized + debuginfo]](https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles) target(s) in 0.12s
     Running `target/debug/statix check -s`
[00] Error: Syntax error
   ╭─[ <stdin>:1:1 ]
   │
 1 │
   │ │
   │ ╰─ Unexpected end of file

@daschinmoy21 daschinmoy21 force-pushed the fix-empty-stdin-crash-moly branch 4 times, most recently from e647aa6 to 9b5d439 Compare April 25, 2026 10:20
- Add missing Stdio import in _utils.rs to fix compile error
- Fix indentation in test_cli_stdin function
- Update CliReport::build to use ariadne 0.6.0 range tuple API
- Add tests for empty stdin and empty file error handling
@daschinmoy21 daschinmoy21 force-pushed the fix-empty-stdin-crash-moly branch from 5d36332 to 2f77f36 Compare April 25, 2026 10:33
Comment thread bin/src/traits.rs Outdated
Replace manual min-offset computation with Report::total_diagnostic_range(),
passing the full diagnostic range to CliReport::build instead of a zero-width
span. This gives ariadne accurate span information for the report header.
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.

Crash when passing empty string in stdin

2 participants