Crates.io | pretty-error-debug |
lib.rs | pretty-error-debug |
version | |
source | src |
created_at | 2022-12-21 12:54:44.018144 |
updated_at | 2024-12-04 06:05:33.229884 |
description | If the process ends with an `Error`, write out the `Error` message and chain. |
homepage | |
repository | https://github.com/Kijewski/pretty-error-debug |
max_upload_size | |
id | 743149 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Display a the chain of an error. Most useful as Result<(), E>
for your fn main()
,
and in conjunction with thiserror
.
This crate simply plagiarized extracted all the relevant formatting code from
anyhow
.
Error: Got a 'middle' error
Caused by:
1: A nested error occured
2: 'inner' failed
3: Caught an error: Not implemented, yet.
thiserror
#[derive(pretty_error_debug::Debug, thiserror::Error)]
pub enum MyError {
#[error("Error variant 1 happened")]
Variant1(#[from] Error1),
#[error("Error variant 2 happened")]
Variant2(#[from] Error2),
}
fn main() -> Result<(), MyError> {
...
}
thiserror
, but without a new type#[derive(Debug, thiserror::Error)]
pub enum MyError {
#[error("Error variant 1 happened")]
Variant1(#[from] Error1),
#[error("Error variant 2 happened")]
Variant2(#[from] Error2),
}
fn main() -> Result<(), pretty_error_debug::Wrapper<MyError>> {
...
}
thiserror
use std::error::Error;
use std::fmt::{self, Write};
#[derive(pretty_error_debug::Debug)]
pub enum MyError {
Variant1(Error1),
Variant2(Error2),
}
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MyError::Variant1(_) => write!(f, "Error variant 1 happened"),
MyError::Variant2(_) => write!(f, "Error variant 2 happened"),
}
}
}
impl Error for MyError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
MyError::Variant1(source) => Some(source),
MyError::Variant2(source) => Some(source),
}
}
}
fn main() -> Result<(), MyError> {
...
}