Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printing malformed diagnostic panics #186

Open
stargazing-dino opened this issue Apr 23, 2024 · 3 comments
Open

printing malformed diagnostic panics #186

stargazing-dino opened this issue Apr 23, 2024 · 3 comments
Labels
bug Something isn't working compiler

Comments

@stargazing-dino
Copy link
Contributor

stargazing-dino commented Apr 23, 2024

Here's a fun yarn script that will break the compilation:

title: MyExample
---
one <<s/> y
===

It's invalid Yarn Spinner code to begin with but it's interesting to see how it bricks it.

It's kinda odd because the amount of characters decides whether it breaks or not. By that, I mean play around with adding/removing characters from the text on the left, center and right and it'll "sometimes" compiled but just with error diagnostics.

Here's the error:

thread 'main' panicked at /Users/katzen/.cargo/git/checkouts/yarnspinner-rust-907c57602d311b5a/e1aead0/crates/compiler/src/listeners/error_listener/diagnostic.rs:165:63:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The offending code is here on the unwrap:

let byte_start = char_indices.clone().nth(relative_start).unwrap();

I think it might also break the c# compiler because with their extension (that uses the C# code i think) it turns all text after this red :O

@stargazing-dino stargazing-dino changed the title Compiler crashes with broken script Crashes when printing malformed diagnostic Apr 23, 2024
@stargazing-dino
Copy link
Contributor Author

stargazing-dino commented Apr 23, 2024

🤦🏼‍♂️

Okay so I opened up the debugger and it turns out it's not the compiler that crashes but the printing of the Diagnostic:

let compilation = match compiler.compile() {
    Ok(compilation) => compilation,
    Err(compiler_err) => {
        println!("Failed to compile:");
        for diagnostic in &compiler_err.0 {
            println!("{}", diagnostic);
        }
        continue;
    }
};

Dunno why I didn't notice but the error is a coming from a util that Diagnostic's Display fmt uses.

Anyways, I think the compiler is generating some off ranges but given that it's broken yarn code anyways no need to fix, just wanted to show and tell :)

@janhohenheim
Copy link
Member

Huh, good catch! I wonder how the reference implementation in C# handles this 👀
I'll leave this issue open because at the very least, we should crash a bit more gracefully

@stargazing-dino
Copy link
Contributor Author

I'll briefly think if there's an easy solution for replacing the unwrap but probably not as I think it's a problem with generating the initial ranges.

But yeah not a big deal this issue

@stargazing-dino stargazing-dino changed the title Crashes when printing malformed diagnostic printing malformed diagnostic panics May 17, 2024
@janhohenheim janhohenheim added bug Something isn't working compiler labels Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler
Projects
None yet
Development

No branches or pull requests

2 participants