Compare commits
9 Commits
7ab0496251
...
v0.7.5
Author | SHA1 | Date | |
---|---|---|---|
3bc512ab48 | |||
7d8071d41b
|
|||
1cc4138ec7
|
|||
00517daaaa
|
|||
b941dc9a76 | |||
5da3c83c12
|
|||
a16bee8e37 | |||
a61f00a79d
|
|||
2bd9bd7b8e |
22
CHANGELOG.md
22
CHANGELOG.md
@@ -6,6 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.7.5] - 2025-07-24
|
||||
|
||||
### Added
|
||||
- print big inner
|
||||
|
||||
### Other
|
||||
- more error correction
|
||||
- correct error test to not be as verbose
|
||||
|
||||
## [0.7.4] - 2025-07-24
|
||||
|
||||
### Added
|
||||
- cleanup aggregate error for single error
|
||||
|
||||
## [0.7.3] - 2025-07-24
|
||||
|
||||
### Added
|
||||
- automatic conversion from anyhow::Error and access to aggregate errors
|
||||
|
||||
### Fixed
|
||||
- *(deps)* update all dependencies (#30)
|
||||
|
||||
## [0.7.2] - 2025-06-25
|
||||
|
||||
### Added
|
||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -278,7 +278,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "notmad"
|
||||
version = "0.7.2"
|
||||
version = "0.7.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
@@ -3,7 +3,7 @@ members = ["crates/*"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.7.2"
|
||||
version = "0.7.5"
|
||||
|
||||
[workspace.dependencies]
|
||||
mad = { path = "crates/mad" }
|
||||
|
@@ -11,16 +11,16 @@ mod waiter;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum MadError {
|
||||
#[error("component failed: {0}")]
|
||||
#[error("component: {0:#?}")]
|
||||
Inner(#[source] anyhow::Error),
|
||||
|
||||
#[error("component(s) failed: {run}")]
|
||||
#[error("component: {run:#?}")]
|
||||
RunError { run: anyhow::Error },
|
||||
|
||||
#[error("component(s) failed: {close}")]
|
||||
CloseError { close: anyhow::Error },
|
||||
|
||||
#[error("component(s) failed: {0}")]
|
||||
#[error("component(s): {0}")]
|
||||
AggregateError(AggregateError),
|
||||
|
||||
#[error("setup not defined")]
|
||||
@@ -30,13 +30,33 @@ pub enum MadError {
|
||||
CloseNotDefined,
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for MadError {
|
||||
fn from(value: anyhow::Error) -> Self {
|
||||
Self::Inner(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AggregateError {
|
||||
errors: Vec<MadError>,
|
||||
}
|
||||
|
||||
impl AggregateError {
|
||||
pub fn get_errors(&self) -> &[MadError] {
|
||||
&self.errors
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for AggregateError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if self.errors.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.errors.len() == 1 {
|
||||
return f.write_str(&self.errors.first().unwrap().to_string());
|
||||
}
|
||||
|
||||
f.write_str("MadError::AggregateError: (")?;
|
||||
|
||||
for error in &self.errors {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use notmad::{Component, Mad};
|
||||
use notmad::{Component, Mad, MadError};
|
||||
use rand::Rng;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
@@ -137,3 +137,20 @@ async fn test_can_shutdown_gracefully() -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_can_easily_transform_error() -> anyhow::Result<()> {
|
||||
fn fallible() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn inner() -> Result<(), MadError> {
|
||||
fallible()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
inner()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user