Skip to content

error 🔗

Common error types.

FFIError 🔗

FFIError(error_code: int, message: str)

Bases: RuntimeError

Exception raised when a vAccel runtime error occurs.

Parameters:

Name Type Description Default

error_code 🔗

int

The code associated with the runtime error.

required

message 🔗

str

A message describing the error.

required
Source code in vaccel/error.py
def __init__(self, error_code: int, message: str):
    """Initializes a new `FFIError` object.

    Args:
        error_code: The code associated with the runtime error.
        message: A message describing the error.
    """
    self.code = error_code
    self.message = message

NullPointerError 🔗

NullPointerError(context: str)

Bases: RuntimeError

Exception raised when a C pointer is unexpectedly NULL.

Parameters:

Name Type Description Default

context 🔗

str

Name or description of the variable that was NULL.

required
Source code in vaccel/error.py
def __init__(self, context: str):
    """Initializes a new `NullPointerError` object.

    Args:
        context: Name or description of the variable that was NULL.
    """
    super().__init__(f"Unexpected NULL pointer encountered in {context}")

ptr_or_raise 🔗

ptr_or_raise(ptr: CData, context: str = 'pointer') -> CData

Validates a C pointer and raises an error if it is NULL.

Parameters:

Name Type Description Default

ptr 🔗

CData

A CFFI pointer to validate.

required

context 🔗

str

A description of the pointer or its role for debugging purposes.

'pointer'

Returns:

Type Description
CData

The original ptr if it is not NULL.

Raises:

Type Description
NullPointerError

If ptr is NULL.

Source code in vaccel/error.py
def ptr_or_raise(ptr: ffi.CData, context: str = "pointer") -> ffi.CData:
    """Validates a C pointer and raises an error if it is NULL.

    Args:
        ptr: A CFFI pointer to validate.
        context: A description of the pointer or its role for debugging
            purposes.

    Returns:
        The original `ptr` if it is not NULL.

    Raises:
        NullPointerError: If `ptr` is NULL.
    """
    if ptr == ffi.NULL:
        raise NullPointerError(context)
    return ptr