mod status

module status

Error handling following the metatensor pattern.

This module provides three components that work together to give C/C++ callers safe, informative error reporting from Rust:

  1. ``rgpot_status_t`` — An integer-valued enum returned from every extern "C" function. RGPOT_SUCCESS (0) means the call succeeded; any other value indicates a specific error category.

  2. Thread-local error message — On failure, a human-readable description is stored in a thread-local CString. The C caller retrieves it with rgpot_last_error(). The pointer is valid until the next rgpot_* call on the same thread.

  3. ``catch_unwind`` — A wrapper used inside every extern "C" function to catch Rust panics before they unwind across the FFI boundary (which is undefined behaviour). Caught panics become RGPOT_INTERNAL_ERROR with the panic message stored for retrieval.

Usage from C

rgpot_status_t s = rgpot_potential_calculate(pot, &input, &output);
if (s != RGPOT_SUCCESS) {
    fprintf(stderr, "rgpot error: %s\n", rgpot_last_error());
}

Functions

unsafe extern C fn rgpot_last_error() -> *const c_char

Retrieve a pointer to the last error message for the current thread.

The pointer is valid until the next call to any rgpot_* function on the same thread.

Safety This is intended to be called from C. The returned pointer must not be freed by the caller.

Enums

enum rgpot_status_t

Status codes returned by all C API functions.

RGPOT_SUCCESS

Operation completed successfully.

RGPOT_INVALID_PARAMETER

An invalid parameter was passed (null pointer, wrong size, etc.).

RGPOT_INTERNAL_ERROR

An internal error occurred (e.g. a Rust panic was caught).

RGPOT_RPC_ERROR

An RPC communication error occurred.

RGPOT_BUFFER_SIZE_ERROR

A buffer was too small for the requested operation.