feat: add thiserror anyhow
This commit is contained in:
19
__err/thiserror_anyhow/src/main.rs
Normal file
19
__err/thiserror_anyhow/src/main.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
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!"))?
|
||||
}
|
||||
Reference in New Issue
Block a user