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:
Casey Rodarmor 2018-06-30 22:19:13 -04:00 committed by GitHub
parent 5acc112a97
commit 438b5147fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -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)?;

View File

@ -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,
}