GitHub
deepbox/core

Errors

Custom error classes with descriptive messages for all failure modes. All extend DeepboxError, which extends the built-in Error class.

DeepboxError

extends Error

Base error class for all Deepbox errors. Use this as a catch-all when you want to handle any framework error.

ShapeError

extends DeepboxError

Thrown when tensor shapes are incompatible for an operation (e.g., matrix multiply with mismatched inner dimensions).

BroadcastError

extends DeepboxError

Thrown when tensors cannot be broadcast to a common shape (e.g., shapes [3,4] and [5,6]).

DTypeError

extends DeepboxError

Thrown when an operation receives an unsupported or incompatible data type.

IndexError

extends DeepboxError

Thrown when an index is out of bounds for a tensor dimension.

InvalidParameterError

extends DeepboxError

Thrown when a function parameter fails validation (wrong type, out of range, etc.). Includes the parameter name and received value.

NotFittedError

extends DeepboxError

Thrown when predict() or transform() is called on a model/scaler that has not been fit() yet.

ConvergenceError

extends DeepboxError

Thrown when an iterative algorithm fails to converge within the allowed iterations (e.g., Lasso, KMeans).

DeviceError

extends DeepboxError

Thrown when an operation is attempted on an unsupported device.

MemoryError

extends DeepboxError

Thrown when memory allocation fails (e.g., tensor too large for available memory).

NotImplementedError

extends DeepboxError

Thrown when a feature or code path is not yet implemented.

DataValidationError

extends DeepboxError

Thrown when input data fails validation (e.g., NaN values, empty arrays, invalid config).

errors-example.ts
import { ShapeError, NotFittedError, InvalidParameterError } from "deepbox/core";import { tensor, add } from "deepbox/ndarray";import { StandardScaler } from "deepbox/preprocess";// ShapeError: incompatible shapestry {  add(tensor([1, 2, 3]), tensor([1, 2]));} catch (e) {  if (e instanceof ShapeError) {    console.log(e.message); // Shape mismatch  }}// NotFittedError: model not trainedtry {  const scaler = new StandardScaler();  scaler.transform(tensor([[1, 2]])); // Not fit yet!} catch (e) {  if (e instanceof NotFittedError) {    console.log(e.message);  }}

Error Handling Pattern

  • Catch specific error types for targeted handling: catch (e) { if (e instanceof ShapeError) ... }
  • Catch DeepboxError as a catch-all for any framework error
  • InvalidParameterError includes .paramName and .receivedValue for debugging
  • ShapeError may include .details with expected and actual shapes
  • ConvergenceError may include .details with iterations and tolerance info