Skip to main content

GaiaError

Struct GaiaError 

Source
pub struct GaiaError { /* private fields */ }
Expand description

Gaia error type, wrapping a specific error kind GaiaErrorKind

Box is used here to reduce the size of the enum and improve performance.

Implementations§

Source§

impl GaiaError

Source

pub fn syntax_error( message: impl ToString, location: SourceLocation, ) -> GaiaError

Creates a syntax error

Use this function to create an error when source code parsing encounters a syntax issue.

§Parameters
  • message - Error message describing the specific syntax issue
  • location - Source code location information where the error occurred
§Return Value

Returns a GaiaError instance containing the syntax error information.

§Example
let location = SourceLocation::default();
let error = GaiaError::syntax_error("missing semicolon", location);
Source

pub fn io_error(io_error: Error, url: Url) -> GaiaError

Creates an IO error

Use this function to create an error when file read/write, network request, or other IO operations fail.

§Parameters
  • io_error - The underlying IO error
  • url - URL associated with the IO operation (such as file path or network address)
§Return Value

Returns a GaiaError instance containing the IO error information.

§Example
use gaia_types::GaiaError;
use url::Url;
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
let url = Url::from_file_path("/path/to/file")
    .ok()
    .and_then(|x| Some(x))
    .unwrap_or_else(|| Url::parse("file:///path/to/file").unwrap());
let error = GaiaError::io_error(io_err, url);
Source

pub fn invalid_instruction( instruction: impl ToString, architecture: Architecture, ) -> GaiaError

Creates an invalid instruction error

Use this function to create an error when an unknown or unsupported instruction is parsed.

§Parameters
  • instruction - Invalid instruction string
  • architecture - Architecture to which the instruction belongs
§Return Value

Returns a GaiaError instance containing the invalid instruction error information.

§Example
use gaia_types::{helpers::Architecture, GaiaError};
let error = GaiaError::invalid_instruction("unknown instruction", Architecture::X86);
Source

pub fn unsupported_architecture(architecture: Architecture) -> GaiaError

Creates an unsupported architecture error

Use this function to create an error when attempting to perform an operation on an unsupported architecture.

§Parameters
  • architecture - Unsupported architecture
§Return Value

Returns a GaiaError instance containing the unsupported architecture error information.

§Example
use gaia_types::{helpers::Architecture, GaiaError};
let error = GaiaError::unsupported_architecture(Architecture::ARM32);
Source

pub fn invalid_range(length: usize, expect: usize) -> GaiaError

Creates an invalid range error

Use this function to create an error when the actual data length does not match the expected length.

§Parameters
  • length - Actual length
  • expect - Expected length
§Return Value

Returns a GaiaError instance containing the invalid range error information.

§Example
use gaia_types::GaiaError;
let error = GaiaError::invalid_range(1024, 2048);
Source

pub fn invalid_data(data: impl ToString) -> GaiaError

Creates an invalid data error.

§Parameters
  • data - Description of the invalid data.
§Return Value

Returns a GaiaError instance containing the invalid data error information.

Source

pub fn invalid_magic_head(head: Vec<u8>, expect: Vec<u8>) -> GaiaError

Creates an invalid magic head error.

§Parameters
  • head - The actual magic head.
  • expect - The expected magic head.
§Return Value

Returns a GaiaError instance containing the invalid magic head error information.

Source

pub fn kind(&self) -> &GaiaErrorKind

Returns the kind of error.

Source

pub fn level(&self) -> &Level

Returns the level of error.

Source

pub fn not_implemented(feature: impl ToString) -> GaiaError

Creates a feature not implemented error

Use this function to create an error when a feature that is not yet implemented is called.

§Parameters
  • feature - Description of the unimplemented feature
§Return Value

Returns a GaiaError instance containing the feature not implemented error information.

§Example
let error = GaiaError::not_implemented("PE context creation");
Source

pub fn adapter_error( adapter_name: impl ToString, message: impl ToString, source: Option<Box<GaiaError>>, ) -> GaiaError

Creates an adapter error

§Parameters
  • adapter_name - Adapter name
  • message - Error message
  • source - Optional source error
§Example
let error = GaiaError::adapter_error("PeExportAdapter", "Export failed", None);
Source

pub fn platform_unsupported( platform: impl ToString, operation: impl ToString, ) -> GaiaError

Creates a platform unsupported error

§Parameters
  • platform - Platform name
  • operation - Description of the unsupported operation
§Example
let error = GaiaError::platform_unsupported("WASI", "inline assembly");
Source

pub fn config_error( config_path: Option<impl ToString>, message: impl ToString, ) -> GaiaError

Creates a configuration error

§Parameters
  • config_path - Optional configuration file path
  • message - Error message
§Example
let error = GaiaError::config_error(Some("config.toml"), "configuration file format error");
Source

pub fn unsupported_target(target: CompilationTarget) -> GaiaError

Creates an unsupported compilation target error

§Parameters
  • target - Unsupported compilation target
§Example
let target = CompilationTarget {
    build: Architecture::X86_64,
    host: AbiCompatible::ELF,
    target: ApiCompatible::Gnu,
};
let error = GaiaError::unsupported_target(target);
Source

pub fn compilation_failed( target: CompilationTarget, message: impl ToString, ) -> GaiaError

Creates a compilation failed error

§Parameters
  • target - Compilation target
  • message - Error message
§Example
let target = CompilationTarget {
    build: Architecture::X86_64,
    host: AbiCompatible::ELF,
    target: ApiCompatible::Gnu,
};
let error = GaiaError::compilation_failed(target, "failed to generate bytecode");
Source

pub fn save_error(format: impl ToString, message: impl ToString) -> GaiaError

Creates a save error.

§Parameters
  • format - Save format.
  • message - Error message.
§Return Value

Returns a GaiaError instance containing the save error information.

Source

pub fn unsupported_feature( feature: impl ToString, location: SourceLocation, ) -> GaiaError

Creates an unsupported feature error.

§Parameters
  • feature - Description of the unsupported feature.
  • location - Source code location information where the error occurred.
§Return Value

Returns a GaiaError instance containing the unsupported feature error information.

Source

pub fn custom_error(message: impl ToString) -> GaiaError

Creates a custom error.

§Parameters
  • message - Error message.
§Return Value

Returns a GaiaError instance containing the custom error information.

Source

pub fn unreachable() -> GaiaError

Creates an unreachable error.

Use this function when program execution reaches a theoretically unreachable code path. It automatically captures the caller location.

§Return Value

Returns a GaiaError instance containing the unreachable error information.

§Example
fn example_unreachable() -> Result<(), GaiaError> {
    let value = 1;
    match value {
        1 => Ok(()),
        _ => Err(GaiaError::unreachable()), // This is theoretically unreachable
    }
}
let _ = example_unreachable();
Source

pub fn truncated() -> GaiaError

Creates a truncated data error.

Use this function when parsing binary data that is truncated or incomplete.

§Return Value

Returns a GaiaError instance containing the truncated data error information.

§Example
let error = GaiaError::truncated();

Trait Implementations§

Source§

impl Debug for GaiaError

Implements the Debug trait for GaiaError.

When outputting in Debug format, it delegates to the internal GaiaErrorKind.

Source§

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

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

impl Display for GaiaError

Implements the Display trait for GaiaError.

When outputting in Display format, it delegates to the internal GaiaErrorKind.

Source§

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

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

impl Error for GaiaError

Implements the standard library Error trait for GaiaError.

This allows GaiaError to be used as a standard error type.

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
Source§

impl From<Error> for GaiaError

Source§

fn from(error: Error) -> GaiaError

Converts to this type from the input type.
Source§

impl From<Error> for GaiaError

Source§

fn from(value: Error) -> GaiaError

Converts to this type from the input type.
Source§

impl From<GaiaErrorKind> for GaiaError

Implementation for converting GaiaErrorKind to GaiaError

This conversion automatically wraps the error kind in a Box, as required by the GaiaError struct, reducing memory footprint.

Source§

fn from(error: GaiaErrorKind) -> GaiaError

Converts to this type from the input type.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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