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 <: ExceptionException type for Cargo build failures.
Fields
message::String: Error messagestderr::String: Raw stderr output from cargoproject_path::String: Path to the Cargo project that failed to build
RustCall.CompilationError — Type
CompilationError <: ExceptionException type for Rust compilation errors.
Fields
message::String: Formatted error messageraw_stderr::String: Raw stderr output from rustcsource_code::String: The Rust source code that failed to compilecommand::String: The rustc command that was executedfile_path::String: Source file path (if available)line_number::Int: Line number where error occurred (if available)context::Dict{String, Any}: Additional debugging context
RustCall.DependencyResolutionError — Type
DependencyResolutionError <: ExceptionException type for dependency resolution failures.
Fields
dependency::String: Name of the problematic dependencymessage::String: Error message describing the resolution failure
RustCall.RuntimeError — Type
RuntimeError <: ExceptionException type for Rust runtime errors.
Fields
message::String: Error messagefunction_name::String: Name of the function that failedstack_trace::String: Optional stack trace (default: "")arguments::Vector{Any}: Function arguments that caused the errorlibrary_name::String: Name of the library containing the functioncontext::Dict{String, Any}: Additional debugging context
RustCall.RustError — Type
RustError <: ExceptionException type for Rust-related errors.
Fields
message::String: Error messagecode::Int32: Optional error code (default: 0)original_error::Any: Original typed error value from Rust (default: nothing)
RustCall.RustPanicError — Type
RustPanicError <: ExceptionA 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; apanic_anyof some other type reportsBox<dyn Any>.
What is not caught
- A raw
#[no_mangle] extern "C" fnthe user writes insiderust""". 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, orCARGO_PROFILE_RELEASE_PANIC=abort).catch_unwindcannot catch what does not unwind. RustCall pinspanic = "unwind"in every manifest it writes and in the environment it passes to Cargo; a@rust_cratepointing at a crate that pinsabortitself is the user's decision. - A second panic during Rust's unwind cleanup (a double-panicking
Drop):catch_unwindcannot 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.
Base.showerror — Method
Base.showerror(io::IO, e::CargoBuildError)Display a CargoBuildError in a user-friendly format.
Base.showerror — Method
Base.showerror(io::IO, e::DependencyResolutionError)Display a DependencyResolutionError in a user-friendly format.
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.
Base.showerror — Method
Base.showerror(io::IO, e::RustError)Display a RustError in a user-friendly format.
RustCall._extract_error_line_numbers_impl — Method
_extract_error_line_numbers_impl(stderr::String) -> Vector{Int}Extract line numbers from rustc error output.
RustCall._extract_suggestions_impl — Method
_extract_suggestions_impl(stderr::String) -> Vector{String}Extract helpful suggestions from rustc error output.
RustCall.format_rustc_error — Method
format_rustc_error(stderr::String) -> StringFormat rustc error output to be more readable. Removes redundant information and highlights important parts.
Improvements
- Better error line highlighting
- Context-aware formatting
- Suggestion extraction
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 convertcode::Int32: Error code to use if the result is Err
Returns
- The Ok value of type
Tif the result is Ok
Throws
RustErrorwith the specified code if the result is Err
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
Tif the result is Ok
Throws
RustErrorif 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"
endRustCall.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)
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.
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.