pub struct Error(/* private fields */);Expand description
An error raised while compiling or evaluating a JSONata expression.
Every error carries a stable JSONata error code (for example S0201 for a syntax error or
T2001 for a type error), so callers can match on codes rather than on messages. Extra
details (such as token or value) fill in the code’s message template.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(code: impl Into<String>) -> Self
pub fn new(code: impl Into<String>) -> Self
Creates an error with the given code and no details.
Sourcepub fn with(self, key: &str, value: impl Into<JsonValue>) -> Self
pub fn with(self, key: &str, value: impl Into<JsonValue>) -> Self
Adds a detail used by the message template (for example token or value).
Sourcepub fn message(&self) -> String
pub fn message(&self) -> String
The human-readable message, built from the code’s template and the error details.
Sourcepub fn position(&self) -> Option<usize>
pub fn position(&self) -> Option<usize>
Position in the expression source where the error was detected, if known.
Like jsonata-js, this is an offset in UTF-16 code units, usually pointing just after the
offending token. Use Error::span for byte ranges.
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)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()