20 lines
395 B
Rust
20 lines
395 B
Rust
use thiserror::Error;
|
|
use anyhow::{Context, Result};
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum SimpleError {
|
|
#[error("error status")]
|
|
ErrorStatus(u32),
|
|
#[error("unknown error")]
|
|
Unknown,
|
|
}
|
|
|
|
fn main() {
|
|
do_something().unwrap();
|
|
}
|
|
|
|
fn do_something() -> Result<String, Box<dyn std::error::Error>> {
|
|
|
|
Err(Box::new(SimpleError::Unknown)).with_context(|| format!("Error unknown!"))?
|
|
}
|