diff --git a/Cargo.lock b/Cargo.lock index 3a4925d2db..28f48ae612 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2074,9 +2074,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.35.1" +version = "1.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c985c1bef99cf13c58fade470483d81a2bfe846ebde60ed28cc2dddec2df9e2" +checksum = "0a7c22c4d34ef4788c351e971c52bfdfe7ea2766f8c5466bc175dd46e52ac22e" dependencies = [ "console", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 4621238457..c994e45e13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,7 +91,7 @@ httpmock = "0.7.0" pretty_assertions = "1.4.0" stripmargin = "0.1.1" markdown = "1.0.0-alpha.16" -insta = { version = "1.35.1", features = ["json"] } +insta = { version = "1.36.1", features = ["json"] } tempfile = "3.10.1" temp-env = "0.3.6" diff --git a/npm/package-lock.json b/npm/package-lock.json index 47cff79659..feb52a103c 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -819,9 +819,9 @@ } }, "node_modules/type-fest": { - "version": "4.10.3", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.10.3.tgz", - "integrity": "sha512-JLXyjizi072smKGGcZiAJDCNweT8J+AuRxmPZ1aG7TERg4ijx9REl8CNhbr36RV4qXqL1gO1FF9HL8OkVmmrsA==", + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.11.0.tgz", + "integrity": "sha512-DPsoHKtnCUqqoB5Y4OPyat7ObSLz1XOkhHTmz+gOkz2p1xs+BBneTvHWriTwc313eozfBWh8b45EpaV3ZrrPPQ==", "engines": { "node": ">=16" }, diff --git a/src/cli/error.rs b/src/cli/error.rs index a13fc34dfd..1b09b1c756 100644 --- a/src/cli/error.rs +++ b/src/cli/error.rs @@ -84,34 +84,19 @@ fn bullet(str: &str) -> String { impl Display for CLIError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let error_prefix = "Error: "; let default_padding = 2; - let root_padding_size = if self.is_root { - error_prefix.len() + + let message_color = if self.is_root { + colored::Color::Yellow } else { - default_padding + colored::Color::White }; - if self.is_root { - f.write_str(self.colored(error_prefix, colored::Color::Red).as_str())?; - } - - f.write_str(&self.message.to_string())?; + f.write_str(self.colored(&self.message, message_color).as_str())?; if let Some(description) = &self.description { - f.write_str("\n")?; - let color = if self.is_root { - colored::Color::Yellow - } else { - colored::Color::White - }; - f.write_str( - margin( - &self.colored(format!("❯ {}", description).as_str(), color), - root_padding_size, - ) - .as_str(), - )?; + f.write_str(&self.colored(": ", message_color))?; + f.write_str(&self.colored(description.to_string().as_str(), colored::Color::White))?; } if !self.trace.is_empty() { @@ -129,9 +114,12 @@ impl Display for CLIError { } if !self.caused_by.is_empty() { - f.write_str(self.dimmed("\nCaused by:\n").as_str())?; + f.write_str("\n")?; + f.write_str(self.dimmed("Caused by:").as_str())?; + f.write_str("\n")?; for (i, error) in self.caused_by.iter().enumerate() { let message = &error.to_string(); + f.write_str(&margin(bullet(message.as_str()).as_str(), default_padding))?; if i < self.caused_by.len() - 1 { @@ -263,7 +251,7 @@ mod tests { #[test] fn test_title() { let error = CLIError::new("Server could not be started"); - let expected = r"Error: Server could not be started".strip_margin(); + let expected = r"Server could not be started".strip_margin(); assert_eq!(error.to_string(), expected); } @@ -271,9 +259,7 @@ mod tests { fn test_title_description() { let error = CLIError::new("Server could not be started") .description("The port is already in use".to_string()); - let expected = r"|Error: Server could not be started - | ❯ The port is already in use" - .strip_margin(); + let expected = r"|Server could not be started: The port is already in use".strip_margin(); assert_eq!(error.to_string(), expected); } @@ -284,9 +270,9 @@ mod tests { .description("The port is already in use".to_string()) .trace(vec!["@server".into(), "port".into()]); - let expected = r"|Error: Server could not be started - | ❯ The port is already in use [at @server.port]" - .strip_margin(); + let expected = + r"|Server could not be started: The port is already in use [at @server.port]" + .strip_margin(); assert_eq!(error.to_string(), expected); } @@ -303,7 +289,7 @@ mod tests { "baseURL".into(), ])]); - let expected = r"|Error: Configuration Error + let expected = r"|Configuration Error |Caused by: | • Base URL needs to be specified [at User.posts.@http.baseURL]" .strip_margin(); @@ -342,12 +328,11 @@ mod tests { ]), ]); - let expected = r"|Error: Configuration Error + let expected = r"|Configuration Error |Caused by: | • Base URL needs to be specified [at User.posts.@http.baseURL] | • Base URL needs to be specified [at Post.users.@http.baseURL] - | • Base URL needs to be specified - | ❯ Set `baseURL` in @http or @server directives [at Query.users.@http.baseURL] + | • Base URL needs to be specified: Set `baseURL` in @http or @server directives [at Query.users.@http.baseURL] | • Base URL needs to be specified [at Query.posts.@http.baseURL]" .strip_margin(); @@ -361,10 +346,9 @@ mod tests { .trace(vec!["Query", "users", "@http", "baseURL"]); let valid = ValidationError::from(cause); let error = CLIError::from(valid); - let expected = r"|Error: Invalid Configuration + let expected = r"|Invalid Configuration |Caused by: - | • Base URL needs to be specified - | ❯ Set `baseURL` in @http or @server directives [at Query.users.@http.baseURL]" + | • Base URL needs to be specified: Set `baseURL` in @http or @server directives [at Query.users.@http.baseURL]" .strip_margin(); assert_eq!(error.to_string(), expected); diff --git a/src/cli/tc.rs b/src/cli/tc.rs index 3843ec36ba..848ac44f0f 100644 --- a/src/cli/tc.rs +++ b/src/cli/tc.rs @@ -193,13 +193,13 @@ fn logger_init() { .format(|buf, record| { let level = record.level(); let color_styles = buf.default_level_style(level); - writeln!( buf, "{color_styles}[{}]{color_styles:#} {}", record.level(), record.args(), )?; + Ok(()) }) .init(); diff --git a/src/main.rs b/src/main.rs index eb14b12196..c82f44d108 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ fn main() -> anyhow::Result<()> { CLIError::new(&error.to_string()).caused_by(sources) } }; - eprintln!("{}", cli_error.color(true)); + log::error!("{}", cli_error.color(true)); std::process::exit(exitcode::CONFIG); } }