Skip to content

Commit

Permalink
Merge branch 'main' into feat/#846/create-call-operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored Mar 4, 2024
2 parents 6b31712 + 64f0f71 commit 045d9bd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 21 additions & 37 deletions src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down Expand Up @@ -263,17 +251,15 @@ 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);
}

#[test]
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);
}
Expand All @@ -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);
}
Expand All @@ -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 [email protected]]"
.strip_margin();
Expand Down Expand Up @@ -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 [email protected]]
| • Base URL needs to be specified [at [email protected]]
| • Base URL needs to be specified
| ❯ Set `baseURL` in @http or @server directives [at [email protected]]
| • Base URL needs to be specified: Set `baseURL` in @http or @server directives [at [email protected]]
| • Base URL needs to be specified [at [email protected]]"
.strip_margin();

Expand All @@ -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 [email protected]]"
| • Base URL needs to be specified: Set `baseURL` in @http or @server directives [at [email protected]]"
.strip_margin();

assert_eq!(error.to_string(), expected);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/tc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 045d9bd

Please sign in to comment.