Skip to content

Commit

Permalink
fix: simplify multi error output
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Jan 4, 2025
1 parent dc7f021 commit f62fcb9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
13 changes: 4 additions & 9 deletions src/multi_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@
#[diagnostic()]
pub struct MultiError {
message: String,
#[diagnostic_source]
errors: ErrList,
#[related]
errors: Vec<miette::Report>,
}

#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("Something went wrong")]
#[diagnostic()]
pub struct ErrList(#[related] Vec<miette::Report>);

impl MultiError {
pub fn new(message: impl Into<String>, errors: Vec<miette::Report>) -> Self {
Self {
message: message.into(),
errors: ErrList(errors),
errors,
}
}
}
impl From<miette::Report> for MultiError {
fn from(report: miette::Report) -> Self {
Self {
message: "Something went wrong".to_string(),
errors: ErrList(vec![report]),
errors: vec![report],
}
}
}
21 changes: 10 additions & 11 deletions src/snapshots/yolk__yolk__test__deployment_error.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ source: src/yolk.rs
expression: render_error(yolk.sync_egg_deployment(&egg).unwrap_err())
---
× Failed to deploy egg bar
╰─▶ × Something went wrong

Error:
× Failed to deploy /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
├─▶ Failed to create symlink at /tmp/[tmp-dir]/[filename] -> /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
╰─▶ File exists (os error 17)

Error:
× Failed to deploy /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
├─▶ Failed to create symlink at /tmp/[tmp-dir]/[filename] -> /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
╰─▶ File exists (os error 17)

Error:
× Failed to deploy /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
├─▶ Failed to create symlink at /tmp/[tmp-dir]/[filename] -> /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
╰─▶ File exists (os error 17)

Error:
× Failed to deploy /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
├─▶ Failed to create symlink at /tmp/[tmp-dir]/[filename] -> /tmp/[tmp-dir]/yolk/eggs/bar/[filename]
╰─▶ File exists (os error 17)
11 changes: 6 additions & 5 deletions src/yolk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@ impl Yolk {
}

/// Deploy or undeploy the given egg, depending on the current system state and the given Egg data.
pub fn sync_egg_deployment(&self, egg: &Egg) -> Result<(), MultiError> {
/// Returns true if the egg is now deployed, false if it is not.
pub fn sync_egg_deployment(&self, egg: &Egg) -> Result<bool, MultiError> {
let deployed = egg
.is_deployed()
.with_context(|| format!("Failed to check deployment state for egg {}", egg.name()))?;
tracing::debug!(
egg.name = egg.name(),
egg.deployed = deployed,
egg.enabled = egg.config().enabled,
"Syncing egg deployment"
"Checking egg deployment"
);
let mappings = egg
.config()
Expand All @@ -134,17 +135,17 @@ impl Yolk {
if result.is_ok() {
tracing::info!("Successfully deployed egg {}", egg.name());
}
result
result.map(|()| true)
} else if !egg.config().enabled && deployed {
cov_mark::hit!(undeploy);
tracing::debug!("Removing egg {}", egg.name());
let result = self.undeploy_egg(egg, &mappings);
if result.is_ok() {
tracing::info!("Successfully undeployed egg {}", egg.name());
}
result
result.map(|()| false)
} else {
Ok(())
Ok(deployed)
}
}

Expand Down

0 comments on commit f62fcb9

Please sign in to comment.