Errors

The exception types RustCall raises. RustCall.RustPanicError is a Rust panic! caught at the FFI boundary; see Panics, Visibility and Lifetime for which panics are caught.

Errors (src/ffi/exceptions.jl)

RustCall.CargoBuildError — Type
CargoBuildError <: Exception

Exception type for Cargo build failures.

Fields

  • message::String: Error message
  • stderr::String: Raw stderr output from cargo
  • project_path::String: Path to the Cargo project that failed to build
source
RustCall.CompilationError — Type
CompilationError <: Exception

Exception type for Rust compilation errors.

Fields

  • message::String: Formatted error message
  • raw_stderr::String: Raw stderr output from rustc
  • source_code::String: The Rust source code that failed to compile
  • command::String: The rustc command that was executed
  • file_path::String: Source file path (if available)
  • line_number::Int: Line number where error occurred (if available)
  • context::Dict{String, Any}: Additional debugging context
source
RustCall.DependencyResolutionError — Type
DependencyResolutionError <: Exception

Exception type for dependency resolution failures.

Fields

  • dependency::String: Name of the problematic dependency
  • message::String: Error message describing the resolution failure
source
RustCall.RuntimeError — Type
RuntimeError <: Exception

Exception type for Rust runtime errors.

Fields

  • message::String: Error message
  • function_name::String: Name of the function that failed
  • stack_trace::String: Optional stack trace (default: "")
  • arguments::Vector{Any}: Function arguments that caused the error
  • library_name::String: Name of the library containing the function
  • context::Dict{String, Any}: Additional debugging context
source
RustCall.RustError — Type
RustError <: Exception

Exception type for Rust-related errors.

Fields

  • message::String: Error message
  • code::Int32: Optional error code (default: 0)
  • original_error::Any: Original typed error value from Rust (default: nothing)
source
RustCall.RustPanicError — Type
RustPanicError <: Exception

A Rust panic! that was caught at the FFI boundary (#244).

Every extern "C" wrapper RustCall generates runs the user's body inside std::panic::catch_unwind. On a panic the wrapper records the message in its own thread-local channel, returns a sentinel, and the Julia side raises this exception instead of letting the unwind reach the boundary — where, since Rust 1.81, it would abort the whole process. So a panic!, a failed assert!, an unwrap() on None or an out-of-bounds index in Rust is now a catchable Julia exception and the session survives.

Fields

  • func_name::String — the Julia-facing name of the function that panicked.
  • message::String — the panic payload, as Rust formatted it. panic! with a literal or with arguments both carry text; a panic_any of some other type reports Box<dyn Any>.

What is not caught

  • A raw #[no_mangle] extern "C" fn the user writes inside rust""". RustCall generates no wrapper for it, so there is no boundary to catch at, and the process aborts. Annotate the function with #[julia] to get the boundary.
  • A crate built under panic = "abort" (its own profile, or CARGO_PROFILE_RELEASE_PANIC=abort). catch_unwind cannot catch what does not unwind. RustCall pins panic = "unwind" in every manifest it writes and in the environment it passes to Cargo; a @rust_crate pointing at a crate that pins abort itself is the user's decision.
  • A second panic during Rust's unwind cleanup (a double-panicking Drop): catch_unwind cannot contain it.

Generated field accessors and clone helpers are behind the same boundary and raise this exception. A panic inside a Drop implementation run by a generated destructor is caught too; when the destructor runs from a finalizer it cannot raise, so it is counted in finalizer_failure_count() instead.

See docs/src/panics.md for the full semantics matrix.

Note

RustError is a concrete struct, so this cannot be a subtype of it. Catch RustPanicError by name, or Exception for both.

source
Base.showerror — Method
Base.showerror(io::IO, e::CargoBuildError)

Display a CargoBuildError in a user-friendly format.

source
Base.showerror — Method
Base.showerror(io::IO, e::DependencyResolutionError)

Display a DependencyResolutionError in a user-friendly format.

source
Base.showerror — Method
Base.showerror(io::IO, e::RuntimeError)

Display a RuntimeError in a user-friendly format with enhanced stack trace. Enhanced with argument information and debugging context.

source
Base.showerror — Method
Base.showerror(io::IO, e::RustError)

Display a RustError in a user-friendly format.

source
RustCall.format_rustc_error — Method
format_rustc_error(stderr::String) -> String

Format rustc error output to be more readable. Removes redundant information and highlights important parts.

Improvements

  • Better error line highlighting
  • Context-aware formatting
  • Suggestion extraction
source
RustCall.result_to_exception — Method
result_to_exception(result::RustResult{T, E}, code::Int32) where {T, E}

Convert a RustResult to either return the Ok value or throw a RustError with a specific error code.

Arguments

  • result::RustResult{T, E}: The Rust result to convert
  • code::Int32: Error code to use if the result is Err

Returns

  • The Ok value of type T if the result is Ok

Throws

  • RustError with the specified code if the result is Err
source
RustCall.result_to_exception — Method
result_to_exception(result::RustResult{T, E}) where {T, E}

Convert a RustResult to either return the Ok value or throw a RustError.

Arguments

  • result::RustResult{T, E}: The Rust result to convert

Returns

  • The Ok value of type T if the result is Ok

Throws

  • RustError if the result is Err

Example

result = RustResult{Int32, String}(false, "division by zero")
try
    value = result_to_exception(result)
catch e
    @assert e isa RustError
    println(e.message)  # => "division by zero"
end
source
RustCall.suggest_fix_for_error — Method
suggest_fix_for_error(stderr::String, source_code::String) -> Vector{String}

Analyze compilation error and suggest potential fixes.

Returns

  • Vector of suggested fixes (strings)
source
RustCall.unwrap_or_throw — Method
unwrap_or_throw(result::RustResult{T, E}, code::Int32) where {T, E}

Alias for result_to_exception with error code.

source
RustCall.unwrap_or_throw — Method
unwrap_or_throw(result::RustResult{T, E}) where {T, E}

Alias for result_to_exception that throws a RustError on Err.

This is a convenience function that provides a more Rust-like naming convention.

source