Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wicketd] replace snafu with thiserror #4950

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ slog-envlogger = "2.2"
slog-error-chain = { git = "https://github.com/oxidecomputer/slog-error-chain", branch = "main", features = ["derive"] }
slog-term = "2.9"
smf = "0.2"
snafu = "0.7"
sp-sim = { path = "sp-sim" }
sprockets-common = { git = "http://github.com/oxidecomputer/sprockets", rev = "77df31efa5619d0767ffc837ef7468101608aee9" }
sprockets-host = { git = "http://github.com/oxidecomputer/sprockets", rev = "77df31efa5619d0767ffc837ef7468101608aee9" }
Expand Down
1 change: 0 additions & 1 deletion wicketd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ tokio-stream.workspace = true
tokio-util.workspace = true
tough.workspace = true
trust-dns-resolver.workspace = true
snafu.workspace = true
toml.workspace = true
uuid.workspace = true

Expand Down
36 changes: 25 additions & 11 deletions wicketd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

//! Configuration related types used by wicketd
use camino::{Utf8Path, Utf8PathBuf};
use dropshot::ConfigLogging;
use serde::{Deserialize, Serialize};
use snafu::prelude::*;
use std::path::Path;
use std::path::PathBuf;
use thiserror::Error;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
Expand All @@ -19,17 +18,32 @@ impl Config {
/// Load a `Config` from the given TOML file
///
/// This config object can be used to create a wicketd server.
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Config, ConfigError> {
pub fn from_file<P: AsRef<Utf8Path>>(
path: P,
) -> Result<Config, ConfigError> {
let path = path.as_ref();
let data = std::fs::read_to_string(path).context(IoSnafu { path })?;
toml::from_str(&data).context(ParseSnafu { path })
let data = std::fs::read_to_string(path).map_err(|error| {
ConfigError::Io { error, path: path.to_owned() }
})?;
toml::from_str(&data).map_err(|error| ConfigError::Parse {
error,
path: path.to_owned(),
})
}
}

#[derive(Debug, Snafu)]
#[derive(Debug, Error)]
pub enum ConfigError {
#[snafu(display("Failed to read config file: {}", path.display()))]
Io { source: std::io::Error, path: PathBuf },
#[snafu(display("Failed to parse config file: {}", path.display()))]
Parse { source: toml::de::Error, path: PathBuf },
#[error("Failed to read config file: {path}")]
Io {
#[source]
error: std::io::Error,
path: Utf8PathBuf,
},
#[error("Failed to parse config file: {path}")]
Parse {
#[source]
error: toml::de::Error,
path: Utf8PathBuf,
},
}
Loading