Skip to main content

BopError

Struct BopError 

Source
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: bool

Fatal 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: bool

True 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

Source

pub fn runtime(message: impl Into<String>, line: u32) -> Self

Create a runtime error at the given source line.

Source

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

pub fn fatal(message: impl Into<String>, line: u32) -> Self

Create a fatal runtime error at the given source line. Used for resource-limit violations (too many steps, Memory limit exceeded) — see BopError::is_fatal for why those must never be swallowed by try_call.

Source§

impl BopError

Source

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 Clone for BopError

Source§

fn clone(&self) -> BopError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BopError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for BopError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for BopError

Available on non-crate feature no_std only.
1.30.0 · Source§

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

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.