diff --git a/Cargo.toml b/Cargo.toml index d4c2a11..d6c0192 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,7 @@ derive_more = { version = "1.0.0-beta.6", features = [ "from", ] } derive-with = "0.5" +thiserror = "1.0" # file watcher inotify = "0.10" diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index 6e4e528..11d47e7 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -44,6 +44,7 @@ ulid = { workspace = true } # boilerplate derive_more = { workspace = true } derive-with = { workspace = true } +thiserror = { workspace = true } # # # file watcher # inotify = { workspace = true } diff --git a/crates/config/src/server.rs b/crates/config/src/server.rs index 7dc43f4..f08f83f 100644 --- a/crates/config/src/server.rs +++ b/crates/config/src/server.rs @@ -13,14 +13,17 @@ use tracing::info; use crate::{ForgeAlias, ForgeConfig, RepoAlias}; -#[derive(Debug, derive_more::From, derive_more::Display)] +#[derive(Debug, thiserror::Error)] pub enum Error { - Io(std::io::Error), - KxIoFs(kxio::fs::Error), - TomlDe(toml::de::Error), - AddressParse(std::net::AddrParseError), + #[error("fs: {0}")] + KxioFs(#[from] kxio::fs::Error), + + #[error("deserialise toml: {0}")] + TomlDe(#[from] toml::de::Error), + + #[error("parse IP addres/port: {0}")] + AddressParse(#[from] std::net::AddrParseError), } -impl std::error::Error for Error {} type Result = core::result::Result; @@ -39,7 +42,7 @@ impl ServerConfig { let file = fs.base().join("git-next-server.toml"); info!(?file, ""); let str = fs.file_read_to_string(&file)?; - toml::from_str(&str).map_err(Into::into) + Ok(toml::from_str(&str)?) } pub fn forges(&self) -> impl Iterator { diff --git a/crates/config/src/tests/mod.rs b/crates/config/src/tests.rs similarity index 100% rename from crates/config/src/tests/mod.rs rename to crates/config/src/tests.rs diff --git a/crates/config/src/webhook/auth.rs b/crates/config/src/webhook/auth.rs index ab619b8..2e4e1ff 100644 --- a/crates/config/src/webhook/auth.rs +++ b/crates/config/src/webhook/auth.rs @@ -1,9 +1,8 @@ -use std::str::FromStr as _; - #[derive(Clone, Debug, PartialEq, Eq, derive_more::Deref, derive_more::Display)] pub struct WebhookAuth(ulid::Ulid); impl WebhookAuth { pub fn new(authorisation: &str) -> Result { + use std::str::FromStr as _; let id = ulid::Ulid::from_str(authorisation)?; tracing::info!("Parse auth token: {}", id); Ok(Self(id)) @@ -21,30 +20,3 @@ impl WebhookAuth { self.0.to_bytes() } } - -#[cfg(test)] -mod tests { - use crate::WebhookAuth; - - #[test] - fn bytes() -> Result<(), Box> { - let ulid = ulid::Ulid::new(); - - let wa = WebhookAuth::new(ulid.to_string().as_str())?; - - assert_eq!(ulid.to_bytes(), wa.to_bytes()); - - Ok(()) - } - - #[test] - fn string() -> Result<(), Box> { - let ulid = ulid::Ulid::new(); - - let wa = WebhookAuth::new(ulid.to_string().as_str())?; - - assert_eq!(ulid.to_string(), wa.to_string()); - - Ok(()) - } -} diff --git a/crates/config/src/webhook/mod.rs b/crates/config/src/webhook/mod.rs index 34295c0..91de1c7 100644 --- a/crates/config/src/webhook/mod.rs +++ b/crates/config/src/webhook/mod.rs @@ -3,4 +3,7 @@ pub mod id; pub mod message; pub mod push; +#[cfg(test)] +mod tests; + pub use push::Push; diff --git a/crates/config/src/webhook/tests.rs b/crates/config/src/webhook/tests.rs new file mode 100644 index 0000000..c7e1df4 --- /dev/null +++ b/crates/config/src/webhook/tests.rs @@ -0,0 +1,25 @@ +mod auth { + use crate::WebhookAuth; + + #[test] + fn bytes() -> Result<(), Box> { + let ulid = ulid::Ulid::new(); + + let wa = WebhookAuth::new(ulid.to_string().as_str())?; + + assert_eq!(ulid.to_bytes(), wa.to_bytes()); + + Ok(()) + } + + #[test] + fn string() -> Result<(), Box> { + let ulid = ulid::Ulid::new(); + + let wa = WebhookAuth::new(ulid.to_string().as_str())?; + + assert_eq!(ulid.to_string(), wa.to_string()); + + Ok(()) + } +}