1 Commits

Author SHA1 Message Date
cuddle-please
036abcc407 chore(release): 0.8.2
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2025-11-14 01:38:56 +00:00
5 changed files with 46 additions and 102 deletions

View File

@@ -6,15 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.10.0] - 2025-11-15 ## [0.8.2] - 2025-11-14
### Added ### Added
- implement take errors
## [0.9.0] - 2025-11-15
### Added
- mad not properly surfaces panics
- add publish - add publish
- add readme - add readme

34
Cargo.lock generated
View File

@@ -222,7 +222,7 @@ dependencies = [
[[package]] [[package]]
name = "notmad" name = "notmad"
version = "0.10.0" version = "0.8.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@@ -432,18 +432,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.18" version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.18" version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -462,9 +462,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.49.0" version = "1.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
dependencies = [ dependencies = [
"bytes", "bytes",
"libc", "libc",
@@ -490,9 +490,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.18" version = "0.7.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-core", "futures-core",
@@ -503,9 +503,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.44" version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [ dependencies = [
"log", "log",
"pin-project-lite", "pin-project-lite",
@@ -515,9 +515,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-attributes" name = "tracing-attributes"
version = "0.1.31" version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -526,9 +526,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.36" version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"valuable", "valuable",
@@ -547,9 +547,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.22" version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5"
dependencies = [ dependencies = [
"matchers", "matchers",
"nu-ansi-term", "nu-ansi-term",

View File

@@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
version = "0.10.0" version = "0.8.2"
[workspace.dependencies] [workspace.dependencies]
mad = { path = "crates/mad" } mad = { path = "crates/mad" }

View File

@@ -77,11 +77,8 @@
use futures::stream::FuturesUnordered; use futures::stream::FuturesUnordered;
use futures_util::StreamExt; use futures_util::StreamExt;
use std::{error::Error, fmt::Display, sync::Arc}; use std::{fmt::Display, sync::Arc, error::Error};
use tokio::{ use tokio::signal::unix::{SignalKind, signal};
signal::unix::{SignalKind, signal},
task::JoinError,
};
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
@@ -104,13 +101,15 @@ pub enum MadError {
/// Error that occurred during the run phase of a component. /// Error that occurred during the run phase of a component.
#[error(transparent)] #[error(transparent)]
RunError { run: anyhow::Error }, RunError {
run: anyhow::Error
},
/// Error that occurred during the close phase of a component. /// Error that occurred during the close phase of a component.
#[error("component(s) failed during close")] #[error("component(s) failed during close")]
CloseError { CloseError {
#[source] #[source]
close: anyhow::Error, close: anyhow::Error
}, },
/// Multiple errors from different components. /// Multiple errors from different components.
@@ -166,10 +165,6 @@ impl AggregateError {
pub fn get_errors(&self) -> &[MadError] { pub fn get_errors(&self) -> &[MadError] {
&self.errors &self.errors
} }
pub fn take_errors(self) -> Vec<MadError> {
self.errors
}
} }
impl Display for AggregateError { impl Display for AggregateError {
@@ -185,7 +180,7 @@ impl Display for AggregateError {
writeln!(f, "{} component errors occurred:", self.errors.len())?; writeln!(f, "{} component errors occurred:", self.errors.len())?;
for (i, error) in self.errors.iter().enumerate() { for (i, error) in self.errors.iter().enumerate() {
write!(f, "\n[Component {}] {}", i + 1, error)?; write!(f, "\n[Component {}] {}", i + 1, error)?;
// Print the error chain for each component error // Print the error chain for each component error
let mut source = error.source(); let mut source = error.source();
let mut level = 1; let mut level = 1;
@@ -506,32 +501,11 @@ impl Mad {
tracing::debug!(component = name, "mad running"); tracing::debug!(component = name, "mad running");
let handle = tokio::spawn(async move { comp.run(job_cancellation).await });
tokio::select! { tokio::select! {
_ = cancellation_token.cancelled() => { _ = cancellation_token.cancelled() => {
error_tx.send(CompletionResult { res: Ok(()) , name }).await error_tx.send(CompletionResult { res: Ok(()) , name }).await
} }
res = handle => { res = comp.run(job_cancellation) => {
let res = match res {
Ok(res) => res,
Err(join) => {
match join.source() {
Some(error) => {
Err(MadError::RunError{run: anyhow::anyhow!("component aborted: {:?}", error)})
},
None => {
if join.is_panic(){
Err(MadError::RunError { run: anyhow::anyhow!("component panicked: {}", join) })
} else {
Err(MadError::RunError { run: anyhow::anyhow!("component faced unknown error: {}", join) })
}
},
}
},
};
error_tx.send(CompletionResult { res , name }).await error_tx.send(CompletionResult { res , name }).await
} }
} }
@@ -822,13 +796,13 @@ mod tests {
.context("failed to read configuration") .context("failed to read configuration")
.context("unable to initialize database") .context("unable to initialize database")
.context("service startup failed"); .context("service startup failed");
let mad_error = MadError::Inner(error); let mad_error = MadError::Inner(error);
let display = format!("{}", mad_error); let display = format!("{}", mad_error);
// Should display the top-level error message // Should display the top-level error message
assert!(display.contains("service startup failed")); assert!(display.contains("service startup failed"));
// Test error chain iteration // Test error chain iteration
if let MadError::Inner(ref e) = mad_error { if let MadError::Inner(ref e) = mad_error {
let chain: Vec<String> = e.chain().map(|c| c.to_string()).collect(); let chain: Vec<String> = e.chain().map(|c| c.to_string()).collect();
@@ -844,26 +818,26 @@ mod tests {
fn test_aggregate_error_display() { fn test_aggregate_error_display() {
let error1 = MadError::Inner( let error1 = MadError::Inner(
anyhow::anyhow!("database connection failed") anyhow::anyhow!("database connection failed")
.context("failed to connect to PostgreSQL"), .context("failed to connect to PostgreSQL")
); );
let error2 = MadError::Inner( let error2 = MadError::Inner(
anyhow::anyhow!("port already in use") anyhow::anyhow!("port already in use")
.context("failed to bind to port 8080") .context("failed to bind to port 8080")
.context("web server initialization failed"), .context("web server initialization failed")
); );
let aggregate = MadError::AggregateError(AggregateError { let aggregate = MadError::AggregateError(AggregateError {
errors: vec![error1, error2], errors: vec![error1, error2],
}); });
let display = format!("{}", aggregate); let display = format!("{}", aggregate);
// Check that it shows multiple errors // Check that it shows multiple errors
assert!(display.contains("2 component errors occurred")); assert!(display.contains("2 component errors occurred"));
assert!(display.contains("[Component 1]")); assert!(display.contains("[Component 1]"));
assert!(display.contains("[Component 2]")); assert!(display.contains("[Component 2]"));
// Check that context chains are displayed // Check that context chains are displayed
assert!(display.contains("failed to connect to PostgreSQL")); assert!(display.contains("failed to connect to PostgreSQL"));
assert!(display.contains("database connection failed")); assert!(display.contains("database connection failed"));
@@ -878,7 +852,7 @@ mod tests {
let aggregate = AggregateError { let aggregate = AggregateError {
errors: vec![error], errors: vec![error],
}; };
let display = format!("{}", aggregate); let display = format!("{}", aggregate);
// Single error should be displayed directly // Single error should be displayed directly
assert!(display.contains("single error")); assert!(display.contains("single error"));
@@ -890,9 +864,9 @@ mod tests {
let error = MadError::Inner( let error = MadError::Inner(
anyhow::anyhow!("root cause") anyhow::anyhow!("root cause")
.context("middle layer") .context("middle layer")
.context("top layer"), .context("top layer")
); );
// Test that we can access the error chain // Test that we can access the error chain
if let MadError::Inner(ref e) = error { if let MadError::Inner(ref e) = error {
let chain: Vec<String> = e.chain().map(|c| c.to_string()).collect(); let chain: Vec<String> = e.chain().map(|c| c.to_string()).collect();
@@ -908,13 +882,13 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_component_error_propagation() { async fn test_component_error_propagation() {
struct FailingComponent; struct FailingComponent;
#[async_trait::async_trait] #[async_trait::async_trait]
impl Component for FailingComponent { impl Component for FailingComponent {
fn name(&self) -> Option<String> { fn name(&self) -> Option<String> {
Some("test-component".to_string()) Some("test-component".to_string())
} }
async fn run(&self, _cancel: CancellationToken) -> Result<(), MadError> { async fn run(&self, _cancel: CancellationToken) -> Result<(), MadError> {
Err(anyhow::anyhow!("IO error") Err(anyhow::anyhow!("IO error")
.context("failed to open file") .context("failed to open file")
@@ -922,16 +896,16 @@ mod tests {
.into()) .into())
} }
} }
let result = Mad::builder() let result = Mad::builder()
.add(FailingComponent) .add(FailingComponent)
.cancellation(Some(std::time::Duration::from_millis(100))) .cancellation(Some(std::time::Duration::from_millis(100)))
.run() .run()
.await; .await;
assert!(result.is_err()); assert!(result.is_err());
let error = result.unwrap_err(); let error = result.unwrap_err();
// Check error display // Check error display
let display = format!("{}", error); let display = format!("{}", error);
assert!(display.contains("component initialization failed")); assert!(display.contains("component initialization failed"));

View File

@@ -138,30 +138,6 @@ async fn test_can_shutdown_gracefully() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[tokio::test]
#[traced_test]
async fn test_component_panics_shutdowns_cleanly() -> anyhow::Result<()> {
let res = Mad::builder()
.add_fn({
move |_cancel| async move {
panic!("my inner panic");
}
})
.add_fn(|cancel| async move {
cancel.cancelled().await;
Ok(())
})
.run()
.await;
let err_content = res.unwrap_err().to_string();
assert!(err_content.contains("component panicked"));
assert!(err_content.contains("my inner panic"));
Ok(())
}
#[test] #[test]
fn test_can_easily_transform_error() -> anyhow::Result<()> { fn test_can_easily_transform_error() -> anyhow::Result<()> {
fn fallible() -> anyhow::Result<()> { fn fallible() -> anyhow::Result<()> {