pub struct ErrorInfo {
pub kind: &'static str,
pub message: String,
pub source: Option<String>,
pub line: Option<u32>,
pub module: Option<String>,
pub traceback: Option<String>,
pub cause: Vec<String>,
}Expand description
A classified view of an Error: what broke, where, and why, as
separate fields instead of one interpolated string.
Built on the error path only — the happy path never constructs one — by
parsing what mlua already captured at raise time (position-prefixed
messages and tracebacks), so classification adds no capture cost of its
own. Production diagnostics use the concise fields (kind, source,
line, module, message); the bounded traceback and cause chain
exist for development mode and for error handlers that ask for them.
Fields§
§kind: &'static strThe classified failure: "lua" (a script error), "nitr" (a
nitr.* builtin or Nitr’s own boundary), "module" (a registered
extension module), "timeout", "memory", or "panic". The set is
closed, so branching on it is stable in a way matching on message
text never is — but it is classification, not provenance: "nitr"
and "timeout" are recognized by message shape, so a script that
raises "nitr.db: ..." or the budget message verbatim lands in
those kinds too. It is fit for logging and error pages; no
security decision may rest on it.
message: StringThe message with any position prefix and traceback stripped.
source: Option<String>The chunk that raised the error (the script path when the chunk was loaded from a file), when the message carried a position.
line: Option<u32>The line within source.
module: Option<String>The failing module ("nitr.db", or an extension’s mount name),
when the error crossed the Rust/Lua boundary with attribution.
traceback: Option<String>The Lua call stack at the raise site, innermost first, bounded to
[MAX_TRACEBACK_LINES] frames.
cause: Vec<String>The underlying Rust error chain, outermost first, bounded to
[MAX_CAUSE_DEPTH] entries.
Implementations§
Source§impl ErrorInfo
impl ErrorInfo
Sourcepub fn from_error(err: &Error) -> Self
pub fn from_error(err: &Error) -> Self
Classifies an error into its structured form.
Sourcepub fn from_message(text: &str) -> Self
pub fn from_message(text: &str) -> Self
Classifies an error that arrives as bare text: what a Lua pcall
catches from an error() or a runtime failure (app.lua:21: attempt to call a nil value ..., possibly with an appended
traceback). Rust-side errors keep their full chain and should go
through from_error instead.
Sourcepub fn concise(&self) -> String
pub fn concise(&self) -> String
The concise single-line form used by production diagnostics:
kind: message (source:line).
Sourcepub fn concise_colored(&self) -> String
pub fn concise_colored(&self) -> String
concise with ANSI color: the kind bold red, the
message bold, the location cyan. Callers gate on the destination
being a terminal — this string must never reach an HTTP body or a
log file.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ErrorInfo
impl RefUnwindSafe for ErrorInfo
impl Send for ErrorInfo
impl Sync for ErrorInfo
impl Unpin for ErrorInfo
impl UnsafeUnpin for ErrorInfo
impl UnwindSafe for ErrorInfo
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more