Compare commits
4 Commits
036abcc407
...
v0.10.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 494ec05874 | |||
|
8c0128612f
|
|||
| cbe049b6a2 | |||
|
2d6b14ad77
|
18
CHANGELOG.md
18
CHANGELOG.md
@@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.10.0] - 2025-11-15
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- implement take errors
|
||||||
|
|
||||||
|
## [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
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -222,7 +222,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "notmad"
|
name = "notmad"
|
||||||
version = "0.8.1"
|
version = "0.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ members = ["crates/*"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.8.1"
|
version = "0.10.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
mad = { path = "crates/mad" }
|
mad = { path = "crates/mad" }
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -165,6 +166,10 @@ 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 {
|
||||||
@@ -501,11 +506,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 +844,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 +890,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
|
||||||
|
|||||||
@@ -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<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user