diff --git a/src/lexer.rs b/src/lexer.rs index 772602476d..7208f141a4 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -231,10 +231,14 @@ impl<'src> Lexer<'src> { // The width of the error site to highlight depends on the kind of error: let length = match kind { UnterminatedString | UnterminatedBacktick => { - let Some(kind) = StringKind::from_token_start(self.lexeme()) else { - return self.internal_error("Lexer::error: expected string or backtick token start"); - }; - kind.delimiter().len() + if self.lexeme().starts_with(Self::INTERPOLATION_END) { + Self::INTERPOLATION_END.len() + } else { + let Some(kind) = StringKind::from_token_start(self.lexeme()) else { + return self.internal_error("Lexer::error: expected string or backtick token start"); + }; + kind.delimiter().len() + } } // highlight the full token _ => self.lexeme().len(), diff --git a/tests/format_string.rs b/tests/format_string.rs index 9ca07ab5f1..eb301faf3e 100644 --- a/tests/format_string.rs +++ b/tests/format_string.rs @@ -290,3 +290,19 @@ fn format_string_followed_by_recipe() { ) .success(); } + +#[test] +fn unterminated_format_string_error() { + Test::new() + .justfile("x := f'{{}}") + .stderr( + " + error: unterminated string + ——▶ justfile:1:10 + │ + 1 │ x := f'{{}} + │ ^^ + ", + ) + .failure(); +}