macro_rules! arg_error { ($loc: expr, $($t:tt)*) => { ... }; }
Expand description
Create ErrorKind::InvalidArgument Error from any std::error::Error object. To create Result, use arg_err! instead. The macro also accepts format! like arguments to create one-off errors.
use thiserror::Error;
use pliron::{arg_error, result::{Result, ErrorKind, Error}, location::Location};
#[derive(Error, Debug)]
#[error("sample error")]
pub struct SampleErr;
assert!(
matches!(
arg_error!(Location::Unknown, SampleErr),
Error {
kind: ErrorKind::InvalidArgument,
err,
loc: _,
} if err.is::<SampleErr>()
));
let res_msg: Error = arg_error!(Location::Unknown, "Some formatted {}", 0);
assert_eq!(
res_msg.err.to_string(),
"Some formatted 0"
);