Skip to content
class

ErrorBuilder

ErrorBuilder

Constructs and throws typed exceptions, annotating each message with the owning op name and the current ErrorContext trace.

Every throw helper formats its message as "<op>: <msg> [trace=<chain>]" (the [trace=...] suffix is omitted when the context stack is empty) and then dispatches to the appropriate LucidError subclass. Helpers are marked [[noreturn]] so callers can use them as drop-in replacements for throw without confusing the compiler's control-flow analysis.

ErrorBuilder is stateless beyond the owning op name — it never holds a reference to a tensor and is safe to construct on the stack at the throw site.

See Also

ErrorContext : Owns the thread-local trace that ErrorBuilder consumes. Validator : Layered on top of ErrorBuilder for tensor precondition checks.

Parameters

op_namestd::string, std::string_view, or const char*
Identifier of the op responsible for the throw. Three overloads are provided so call sites can pass whichever literal type is most convenient.

Examples

```
ErrorBuilder("my_op").shape_mismatch(expected, got, "weight tensor");
ErrorBuilder("conv2d").not_implemented("dilation>1 on integer dtypes");
```

Constructors

1
ctor

ErrorBuilder

void ErrorBuilder(int op_name)

Constructs a builder owning the given op name.

Parameters

op_namestd::string
Identifier moved into op_. Used as the prefix of every formatted message produced by this builder.

Methods

9
fnconst

device_mismatch

void device_mismatch(Device expected, Device got, const int & detail)

Throws a DeviceMismatch, converting Device enumerators to their canonical string names before construction.

Parameters

expectedDevice
Required device.
gotDevice
Device actually supplied.
detailconst std::string&= None
Extra annotation appended after the op name when non-empty. Defaults to "".

Raises

DeviceMismatch
Always. This function does not return.
fnconst

dtype_mismatch

void dtype_mismatch(Dtype expected, Dtype got, const int & detail)

Throws a DtypeMismatch, converting Dtype enumerators to their canonical string names before construction.

Parameters

expectedDtype
Required dtype.
gotDtype
Dtype actually supplied.
detailconst std::string&= None
Extra annotation appended after the op name when non-empty. Defaults to "".

Raises

DtypeMismatch
Always. This function does not return.
fnconst

fail

void fail(const int & msg)

Throws a generic LucidError with the message prepended by the op name and the current trace.

Parameters

msgconst std::string&
Human-readable explanation of the failure.

Raises

LucidError
Always. This function does not return.
fnconst

format_with_context

int format_with_context(const int & msg)

Returns "<op_>: <msg> [trace=<chain>]" (the [trace=...] suffix is omitted when the current ErrorContext trace is empty). Used by the throw helpers that take a free-form message.

fnconst

index_error

void index_error(const int & msg)

Throws an IndexError with the op name and trace.

Parameters

msgconst std::string&
Description of the out-of-bounds access (typically the offending index and the valid range).

Raises

IndexError
Always. This function does not return.
fnconst

invalid_argument

void invalid_argument(const int & msg)

Throws an InvalidArgument with the op name and trace.

Parameters

msgconst std::string&
Which argument and the value it may not have.

Raises

InvalidArgument
Always. This function does not return.
fnconst

linalg_error

void linalg_error(const int & msg)

Throws a LinAlgError with the op name and trace.

For a matrix the routine cannot factor (LAPACK's info > 0), not for a malformed argument.

Parameters

msgconst std::string&
The failed step, e.g. the info LAPACK reported.

Raises

LinAlgError
Always. This function does not return.
fnconst

not_implemented

void not_implemented(const int & msg)

Throws a NotImplementedError with the op name and trace.

Use for combinations the engine recognises but does not yet support (e.g. an unsupported dtype on a specific backend).

Parameters

msgconst std::string&
Description of the missing implementation.

Raises

NotImplementedError
Always. This function does not return.
fnconst

shape_mismatch

void shape_mismatch(const int & expected, const int & got, const int & detail)

Throws a ShapeMismatch with the op name, optional detail, and current trace combined as the exception's context field.

Parameters

expectedconst Shape&
Shape the op required.
gotconst Shape&
Shape that was actually supplied.
detailconst std::string&= None
Extra annotation (e.g. "rhs") appended after the op name when non-empty. Defaults to "".

Raises

ShapeMismatch
Always. This function does not return.