pub struct Error(_);
Expand description

An error that may be returned by the Rune native library.

Error Handling

Fallible functions will return a *mut Error which must be checked before continuing.

This might look like…

Runtime *runtime;
Config cfg = {...};

Error *error = rune_runtime_load(&cfg, &runtime);

if (error) {
    const char *msg = rune_error_to_string(error);

    printf("Unable to load the Rune: %s\n", msg);

    free(msg);
    rune_error_free(error);
    exit(1);
}

Additional “return” values are returned via output parameters (typically named xxx_out). If an error occurs, the state of the output parameter is unspecified, otherwise it is guaranteed to be in a valid state.

If an error is present, it is the caller’s responsibility to free it afterwards.

Implementations

Methods from Deref<Target = Error>

Get the backtrace for this Error.

In order for the backtrace to be meaningful, one of the two environment variables RUST_LIB_BACKTRACE=1 or RUST_BACKTRACE=1 must be defined and RUST_LIB_BACKTRACE must not be 0. Backtraces are somewhat expensive to capture in Rust, so we don’t necessarily want to be capturing them all over the place all the time.

  • If you want panics and errors to both have backtraces, set RUST_BACKTRACE=1;
  • If you want only errors to have backtraces, set RUST_LIB_BACKTRACE=1;
  • If you want only panics to have backtraces, set RUST_BACKTRACE=1 and RUST_LIB_BACKTRACE=0.
Stability

Standard library backtraces are only available on the nightly channel. Tracking issue: rust-lang/rust#53487.

On stable compilers, this function is only available if the crate’s “backtrace” feature is enabled, and will use the backtrace crate as the underlying backtrace implementation.

[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }

An iterator of the chain of source errors contained by this Error.

This iterator will visit every error in the cause chain of this error object, beginning with the error that this error object was created from.

Example
use anyhow::Error;
use std::io;

pub fn underlying_io_error_kind(error: &Error) -> Option<io::ErrorKind> {
    for cause in error.chain() {
        if let Some(io_error) = cause.downcast_ref::<io::Error>() {
            return Some(io_error.kind());
        }
    }
    None
}

The lowest level cause of this error — this error’s cause’s cause’s cause etc.

The root cause is the last error in the iterator produced by chain().

Returns true if E is the type held by this error object.

For errors with context, this method returns true if E matches the type of the context C or the type of the error on which the context has been attached. For details about the interaction between context and downcasting, see here.

Downcast this error object by reference.

Example
// If the error was caused by redaction, then return a tombstone instead
// of the content.
match root_cause.downcast_ref::<DataStoreError>() {
    Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),
    None => Err(error),
}

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The archived version of the pointer metadata for this type.

Converts some archived metadata to the pointer metadata for itself.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Deserializes using the given deserializer

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type for metadata in pointers and references to Self.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more