pub struct BopError {
pub line: Option<u32>,
pub column: Option<u32>,
pub message: String,
pub friendly_hint: Option<String>,
pub is_fatal: bool,
pub is_try_return: bool,
}Fields§
§line: Option<u32>§column: Option<u32>§message: String§friendly_hint: Option<String>§is_fatal: boolFatal errors can’t be caught by try_call; they always
unwind to the engine boundary. This is the load-bearing
property that makes BopLimits a real sandbox — a
script can’t wrap an infinite loop in try_call and
loop forever by swallowing the step-limit error.
Non-fatal errors (the default) describe ordinary runtime problems — type mismatches, missing fields, index out of bounds, “function not found”. Those can be caught.
Currently set only on resource-limit errors
(Your code took too many steps, Memory limit exceeded). Any new fatal case must explicitly construct
BopError::fatal rather than BopError::runtime.
is_try_return: boolTrue only for the sentinel error the walker uses to
unwind a try-driven early-return out of an enclosing
fn. When set, the message / line / friendly_hint
fields are unused — the return value lives on the
evaluator’s pending_try_return slot. call_bop_fn
traps errors with this flag and converts them into a
normal Signal::Return.
Always false outside that narrow window. Users and
host code should never construct a BopError with this
flag set; use BopError::runtime / BopError::fatal
for real errors.
Replaces the older "__bop_try_return_signal__" message
sentinel — a field lookup is cheaper than a string
compare, and a flag can never collide with a user
message that happens to spell the same bytes.
Implementations§
Source§impl BopError
impl BopError
Sourcepub fn runtime(message: impl Into<String>, line: u32) -> Self
pub fn runtime(message: impl Into<String>, line: u32) -> Self
Create a runtime error at the given source line.
Sourcepub fn runtime_at(
message: impl Into<String>,
line: u32,
column: Option<NonZeroU32>,
) -> Self
pub fn runtime_at( message: impl Into<String>, line: u32, column: Option<NonZeroU32>, ) -> Self
Create a runtime error at the given line and column.
Callers that have an AST node handy (expr.line,
expr.column) should prefer this over
Self::runtime so the error renderer can point a
carat at the offending character.
Source§impl BopError
impl BopError
Sourcepub fn render(&self, source: &str) -> String
pub fn render(&self, source: &str) -> String
Render the error with an inline source snippet and a
^ carat under the offending position. Needs the full
program source that produced the error — pass the same
string you handed to bop::run / bop::parse.
Falls back gracefully:
- No line set → just the message.
- Line set but out of range (e.g. source was truncated) → message + “[line N]” without the snippet.
- No column set → message + snippet, no carat.
- Column set → message + snippet + carat.
Appends the friendly_hint as a hint: line when
present. Used by bop-cli to render program failures;
embedders can call it from their own error path.
Trait Implementations§
Source§impl Error for BopError
Available on non-crate feature no_std only.
impl Error for BopError
no_std only.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()