Skip to content

fix(cli): prevent ariadne from panicking on empty stdin#161

Open
daschinmoy21 wants to merge 1 commit intooppiliappan:masterfrom
daschinmoy21:fix-empty-stdin-crash
Open

fix(cli): prevent ariadne from panicking on empty stdin#161
daschinmoy21 wants to merge 1 commit intooppiliappan:masterfrom
daschinmoy21:fix-empty-stdin-crash

Conversation

@daschinmoy21
Copy link
Copy Markdown

Fixes #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
   ╭─[<stdin>:1:1]
   │
 1 │
   · │
   · ╰─ Unexpected end of file
───╯

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.
@mightyiam
Copy link
Copy Markdown
Collaborator

You may be interested in submitting this in https://github.com/molybdenumsoftware/statix, if it is not accepted here.

@daschinmoy21
Copy link
Copy Markdown
Author

Ok . Will open a PR for this change there.Thanks.

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