4 Commits

Author SHA1 Message Date
cbe049b6a2 chore(release): v0.9.0 (#36)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.9.0

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: #36
2025-11-15 14:35:36 +01:00
2d6b14ad77 feat: mad not properly surfaces panics
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2025-11-15 14:33:00 +01:00
f777ec9b1e fix(deps): update all dependencies (#38)
All checks were successful
continuous-integration/drone/push Build is passing
2025-11-14 02:38:11 +01:00
2415088792 chore(deps): update rust crate tracing-subscriber to v0.3.20 (#37)
All checks were successful
continuous-integration/drone/push Build is passing
2025-11-13 03:15:23 +01:00
5 changed files with 97 additions and 94 deletions

View File

@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.9.0] - 2025-11-15
### Added
- mad not properly surfaces panics
- add publish
- add readme
### Fixed
- *(deps)* update all dependencies (#38)
### Other
- *(deps)* update rust crate tracing-subscriber to v0.3.20 (#37)
## [0.8.1] - 2025-08-09 ## [0.8.1] - 2025-08-09
### Other ### Other

76
Cargo.lock generated
View File

@@ -195,11 +195,11 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]] [[package]]
name = "matchers" name = "matchers"
version = "0.1.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
dependencies = [ dependencies = [
"regex-automata 0.1.10", "regex-automata",
] ]
[[package]] [[package]]
@@ -239,12 +239,11 @@ dependencies = [
[[package]] [[package]]
name = "nu-ansi-term" name = "nu-ansi-term"
version = "0.46.0" version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [ dependencies = [
"overload", "windows-sys 0.61.2",
"winapi",
] ]
[[package]] [[package]]
@@ -253,12 +252,6 @@ version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.3" version = "0.12.3"
@@ -360,27 +353,6 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "regex"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.9",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.9" version = "0.4.9"
@@ -389,15 +361,9 @@ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-syntax 0.8.5", "regex-syntax",
] ]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.5" version = "0.8.5"
@@ -581,14 +547,14 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.19" 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 = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5"
dependencies = [ dependencies = [
"matchers", "matchers",
"nu-ansi-term", "nu-ansi-term",
"once_cell", "once_cell",
"regex", "regex-automata",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
@@ -645,28 +611,6 @@ dependencies = [
"wit-bindgen-rt", "wit-bindgen-rt",
] ]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-link" name = "windows-link"
version = "0.2.1" version = "0.2.1"

View File

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

View File

@@ -77,8 +77,11 @@
use futures::stream::FuturesUnordered; use futures::stream::FuturesUnordered;
use futures_util::StreamExt; use futures_util::StreamExt;
use std::{fmt::Display, sync::Arc, error::Error}; use std::{error::Error, fmt::Display, sync::Arc};
use tokio::signal::unix::{SignalKind, signal}; use tokio::{
signal::unix::{SignalKind, signal},
task::JoinError,
};
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
@@ -101,15 +104,13 @@ 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 { RunError { run: anyhow::Error },
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.
@@ -501,11 +502,32 @@ 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 = comp.run(job_cancellation) => { res = handle => {
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
} }
} }
@@ -818,13 +840,13 @@ 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 {
@@ -864,7 +886,7 @@ 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

View File

@@ -138,6 +138,30 @@ 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<()> {