Skip to content

Commit ffcff16

Browse files
committed
Add missing CanWrapError section
1 parent 7247714 commit ffcff16

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

content/blog/2025-01-09-v0.3.0-release.md

+17
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ fn main() {
139139

140140
For additional information on `#[cgp_getter]`, refer to the [Generic Accessor Providers](https://patterns.contextgeneric.dev/generic-accessor-providers.html#the-cgp_getter-macro) chapter of the CGP Patterns book.
141141

142+
## `CanWrapError` Trait
143+
144+
A new `CanWrapError` trait has been introduced to simplify the wrapping of existing errors. The trait is defined as follows:
145+
146+
```rust
147+
#[cgp_component {
148+
provider: ErrorWrapper,
149+
}]
150+
pub trait CanWrapError<Detail>: HasErrorType {
151+
fn wrap_error(error: Self::Error, detail: Detail) -> Self::Error;
152+
}
153+
```
154+
155+
Previously, the wrapping approach was to use `CanRaiseError` with a tuple, i.e. `CanRaiseError<(Self::Error, Detail)>`. However, it is quite tedious to wrap errors this way, and thus `CanWrapError` is introduced a cleaner to raise wrapped errors.
156+
157+
More details about the use of `CanWrapError` is available at the [Error Wrapping](https://patterns.contextgeneric.dev/error-wrapping.html) chapter of the CGP Patterns book.
158+
142159
## `cgp-error-anyhow` Crate
143160

144161
We have published a new [`cgp-error-anyhow`](https://docs.rs/cgp-error-anyhow/0.3.0/cgp_error_anyhow/index.html) crate, which provides context-generic error raisers for `anyhow::Error`. This addition complements the previously published [`cgp-error-eyre`](https://docs.rs/cgp-error-eyre/0.3.0/cgp_error_eyre/index.html) and [`cgp-error-std`](https://docs.rs/cgp-error-std/0.3.0/cgp_error_std/index.html) crates, which support CGP error handling with `eyre::Error` and `Box<dyn core::error::Error + Send + Sync + 'static>`. Given the popularity of `anyhow::Error`, this crate extends support for its usage.

0 commit comments

Comments
 (0)