Skip to content

Commit d403fd6

Browse files
committed
Moar
1 parent 385dbc2 commit d403fd6

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ dirs.workspace = true
1111
fs-err.workspace = true
1212
serde.workspace = true
1313
serde_yaml.workspace = true
14-
thiserror.workspace = true
14+
snafu.workspace = true

crates/config/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99

1010
use fs_err as fs;
1111
use serde::{de::DeserializeOwned, Serialize};
12-
use thiserror::Error;
12+
use snafu::{ResultExt as _, Snafu};
1313

1414
const EXTENSION: &str = "yaml";
1515

@@ -74,13 +74,13 @@ impl Manager {
7474

7575
let dir = self.scope.save_dir(&domain);
7676

77-
fs::create_dir_all(&dir).map_err(|io| SaveError::CreateDir(dir.clone(), io))?;
77+
fs::create_dir_all(&dir).context(CreateDirSnafu)?;
7878

7979
let path = dir.join(format!("{name}.{EXTENSION}"));
8080

81-
let serialized = serde_yaml::to_string(config)?;
81+
let serialized = serde_yaml::to_string(config).context(SerializeSnafu)?;
8282

83-
fs::write(&path, serialized).map_err(|io| SaveError::Write(path, io))?;
83+
fs::write(&path, serialized).context(WriteSnafu)?;
8484

8585
Ok(())
8686
}
@@ -97,18 +97,18 @@ impl Manager {
9797
}
9898
}
9999

100-
#[derive(Debug, Error)]
101-
#[error("$HOME or $XDG_CONFIG_HOME env not set")]
100+
#[derive(Debug, Snafu)]
101+
#[snafu(display("$HOME or $XDG_CONFIG_HOME env not set"))]
102102
pub struct CreateUserError;
103103

104-
#[derive(Debug, Error)]
104+
#[derive(Debug, Snafu)]
105105
pub enum SaveError {
106-
#[error("create config dir {0:?}")]
107-
CreateDir(PathBuf, #[source] io::Error),
108-
#[error("serialize config")]
109-
Yaml(#[from] serde_yaml::Error),
110-
#[error("write config file {0:?}")]
111-
Write(PathBuf, #[source] io::Error),
106+
#[snafu(display("create config dir"))]
107+
CreateDir { source: io::Error },
108+
#[snafu(display("serialize config"))]
109+
Serialize { source: serde_yaml::Error },
110+
#[snafu(display("write config file"))]
111+
Write { source: io::Error },
112112
}
113113

114114
fn enumerate_paths(entry: Entry, resolve: Resolve<'_>, domain: &str) -> Vec<PathBuf> {

crates/container/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,13 @@ fn add_mount<T: AsRef<Path>>(
355355
flags,
356356
Option::<&str>::None,
357357
)
358-
.with_context(|_| MountSnafu {
359-
target: target.to_owned(),
360-
})?;
358+
.with_context(|_| MountSnafu { target })?;
361359
Ok(())
362360
}
363361

364362
fn set_current_dir(path: impl AsRef<Path>) -> Result<(), ContainerError> {
365363
let path = path.as_ref();
366-
std::env::set_current_dir(path).with_context(|_| SetCurrentDirSnafu { path: path.to_owned() })
364+
std::env::set_current_dir(path).with_context(|_| SetCurrentDirSnafu { path })
367365
}
368366

369367
fn ignore_sigint() -> Result<(), nix::Error> {

0 commit comments

Comments
 (0)