pub struct EvalError {
pub kind: EvalErrorKind,
pub span: Option<Span>,
pub message: String,
pub source: Option<Arc<dyn Error + Send + Sync>>,
}Expand description
An error that occurs during template evaluation.
Carries a structured EvalErrorKind, a human-readable message,
an optional source Span, and an optional underlying error cause.
§Error chaining
When a host’s EvalContext implementation
catches an underlying error (database, I/O, etc.), it can preserve the
original error chain using with_source:
use weaver_lang::EvalError;
fn example() -> Result<(), EvalError> {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file missing");
Err(EvalError::host_error("failed to load entry").with_source(io_err))
}Fields§
§kind: EvalErrorKind§span: Option<Span>§message: String§source: Option<Arc<dyn Error + Send + Sync>>The underlying error that caused this evaluation error, if any.
Wrapped in Arc so that EvalError remains Clone.
Implementations§
Source§impl EvalError
impl EvalError
pub fn new(kind: EvalErrorKind, message: impl Into<String>) -> Self
pub fn with_span(self, span: Span) -> Self
Sourcepub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Self
pub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Self
Attach an underlying error cause to this evaluation error.
This preserves the full error chain for production logging and
debugging. The source is wrapped in an Arc so that EvalError
remains Clone.
pub fn undefined_variable(scope: &str, name: &str) -> Self
pub fn undefined_processor(namespace: &str, name: &str) -> Self
pub fn undefined_command(name: &str) -> Self
pub fn type_error(expected: &str, got: &str) -> Self
pub fn not_iterable(got: &str) -> Self
pub fn host_error(message: impl Into<String>) -> Self
Trait Implementations§
Source§impl Error for EvalError
impl Error for EvalError
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()
Auto Trait Implementations§
impl !RefUnwindSafe for EvalError
impl !UnwindSafe for EvalError
impl Freeze for EvalError
impl Send for EvalError
impl Sync for EvalError
impl Unpin for EvalError
impl UnsafeUnpin for EvalError
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