Improve invalid escape sequence error messages (#328)
The invalid escape sequence error message is delimited with backticks and isn't used as input to other programs. This diff tweaks the escaping rules slightly when printing invalid escape sequences. In particular, `, \, ', and " are now not be escaped.
This commit is contained in:
parent
5acc112a97
commit
438b5147fe
@ -67,9 +67,16 @@ impl<'a> Display for CompilationError<'a> {
|
|||||||
variable, circle.join(" -> "))?;
|
variable, circle.join(" -> "))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidEscapeSequence{character} => {
|
InvalidEscapeSequence{character} => {
|
||||||
writeln!(f, "`\\{}` is not a valid escape sequence",
|
let representation = match character {
|
||||||
character.escape_default().collect::<String>())?;
|
'`' => r"\`".to_string(),
|
||||||
|
'\\' => r"\".to_string(),
|
||||||
|
'\'' => r"'".to_string(),
|
||||||
|
'"' => r#"""#.to_string(),
|
||||||
|
_ => character.escape_default().collect(),
|
||||||
|
};
|
||||||
|
writeln!(f, "`\\{}` is not a valid escape sequence", representation)?;
|
||||||
}
|
}
|
||||||
DuplicateParameter{recipe, parameter} => {
|
DuplicateParameter{recipe, parameter} => {
|
||||||
writeln!(f, "Recipe `{}` has duplicate parameter `{}`", recipe, parameter)?;
|
writeln!(f, "Recipe `{}` has duplicate parameter `{}`", recipe, parameter)?;
|
||||||
|
@ -1800,3 +1800,18 @@ echo:
|
|||||||
stderr: "echo dotenv-value\necho dotenv-value\n",
|
stderr: "echo dotenv-value\necho dotenv-value\n",
|
||||||
status: EXIT_SUCCESS,
|
status: EXIT_SUCCESS,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
integration_test! {
|
||||||
|
name: invalid_escape_sequence_message,
|
||||||
|
justfile: r#"
|
||||||
|
X = "\'"
|
||||||
|
"#,
|
||||||
|
args: (),
|
||||||
|
stdout: "",
|
||||||
|
stderr: r#"error: `\'` is not a valid escape sequence
|
||||||
|
|
|
||||||
|
2 | X = "\'"
|
||||||
|
| ^^^^
|
||||||
|
"#,
|
||||||
|
status: EXIT_FAILURE,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user