From 438b5147fe79da352b963d0aa681d66a0377a40f Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 30 Jun 2018 22:19:13 -0400 Subject: [PATCH] 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. --- src/compilation_error.rs | 11 +++++++++-- tests/integration.rs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/compilation_error.rs b/src/compilation_error.rs index 4d629a2..0fc9fc5 100644 --- a/src/compilation_error.rs +++ b/src/compilation_error.rs @@ -67,9 +67,16 @@ impl<'a> Display for CompilationError<'a> { variable, circle.join(" -> "))?; } } + InvalidEscapeSequence{character} => { - writeln!(f, "`\\{}` is not a valid escape sequence", - character.escape_default().collect::())?; + let representation = match character { + '`' => 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} => { writeln!(f, "Recipe `{}` has duplicate parameter `{}`", recipe, parameter)?; diff --git a/tests/integration.rs b/tests/integration.rs index cd99977..5bf39be 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1800,3 +1800,18 @@ echo: stderr: "echo dotenv-value\necho dotenv-value\n", 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, +}