fables-tales / rubyfmt

Ruby Autoformatter!
MIT License
1.07k stars 50 forks source link

Prevent internal ruby failure on invalid braces #455

Open reese opened 8 months ago

reese commented 8 months ago

""} is invalid syntax, and while running it, Ripper tries to run on_embexpr_end to try and handle it as if it were the closing brace of an embexpr. However, in that case, we get a NoMethodError for trying to append to an array that isn't there (since we didn't call on_embexpr_beg. This is absolutely a weird edge case, but handling it means we correctly report this as a syntax error instead of an internal ruby error.

(There might be something to do here for a more sustainable solution, which is something like if we run into an internal ruby error, call the parser directly without rubyfmt_lib and see if it parses correctly, but I'll leave that as an idea for a later day.)