pub struct Error { /* private fields */ }Expand description
Unified crate error used by stable public APIs.
§Examples
let err = async_jsonata_rust::Error::new("D3040", "Sqrt domain error");
assert_eq!(err.code(), "D3040");Implementations§
Source§impl Error
impl Error
Sourcepub fn new(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self
Creates a new error with JSONata-compatible code.
§Examples
let err = async_jsonata_rust::Error::new("S0201", "Unexpected token");
assert_eq!(err.code(), "S0201");Sourcepub fn parser(err: ParserError) -> Self
pub fn parser(err: ParserError) -> Self
Creates a parser error from parser internals.
§Examples
let parse_error = async_jsonata_rust::parse_expression("1+", false).unwrap_err();
let err = async_jsonata_rust::Error::from(parse_error);
assert!(!err.code().is_empty());Sourcepub fn runtime(err: JsonError) -> Self
pub fn runtime(err: JsonError) -> Self
Creates a runtime error from evaluator/function internals.
§Examples
let runtime = async_jsonata_rust::JsonError::new("D3040", "Sqrt domain error");
let err = async_jsonata_rust::Error::from(runtime);
assert_eq!(err.code(), "D3040");Sourcepub fn not_implemented(message: impl Into<String>) -> Self
pub fn not_implemented(message: impl Into<String>) -> Self
Creates a not-implemented error for incomplete features.
§Examples
let err = async_jsonata_rust::Error::not_implemented("evaluator pending");
assert_eq!(err.code(), "E0001");Sourcepub fn with_context(self, key: impl Into<String>, value: Value) -> Self
pub fn with_context(self, key: impl Into<String>, value: Value) -> Self
Adds named context field.
§Examples
let err = async_jsonata_rust::Error::new("E1", "oops")
.with_context("field", serde_json::Value::String("value".into()));
assert!(err.context().contains_key("field"));Sourcepub fn code(&self) -> &str
pub fn code(&self) -> &str
Returns JSONata error code (D3040, S0201, …).
Examples found in repository?
examples/basic_eval.rs (line 11)
3fn main() {
4 let parser = Parser::new();
5 match parser.parse("Account.Order[0].Product") {
6 Ok(expr) => {
7 println!("Source: {}", expr.source());
8 println!("AST type: {}", expr.ast()["type"]);
9 }
10 Err(err) => {
11 eprintln!("{}: {}", err.code(), err.message());
12 std::process::exit(1);
13 }
14 }
15}More examples
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Returns human-readable message.
Examples found in repository?
examples/basic_eval.rs (line 11)
3fn main() {
4 let parser = Parser::new();
5 match parser.parse("Account.Order[0].Product") {
6 Ok(expr) => {
7 println!("Source: {}", expr.source());
8 println!("AST type: {}", expr.ast()["type"]);
9 }
10 Err(err) => {
11 eprintln!("{}: {}", err.code(), err.message());
12 std::process::exit(1);
13 }
14 }
15}Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<ParserError> for Error
impl From<ParserError> for Error
Source§fn from(value: ParserError) -> Self
fn from(value: ParserError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more