Errors
DeepboxError
Base error class for all Deepbox errors. Use this as a catch-all when you want to handle any framework error.
ShapeError
Thrown when tensor shapes are incompatible for an operation (e.g., matrix multiply with mismatched inner dimensions).
BroadcastError
Thrown when tensors cannot be broadcast to a common shape (e.g., shapes [3,4] and [5,6]).
DTypeError
Thrown when an operation receives an unsupported or incompatible data type.
IndexError
Thrown when an index is out of bounds for a tensor dimension.
InvalidParameterError
Thrown when a function parameter fails validation (wrong type, out of range, etc.). Includes the parameter name and received value.
NotFittedError
Thrown when predict() or transform() is called on a model/scaler that has not been fit() yet.
ConvergenceError
Thrown when an iterative algorithm fails to converge within the allowed iterations (e.g., Lasso, KMeans).
DeviceError
Thrown when an operation is attempted on an unsupported device.
MemoryError
Thrown when memory allocation fails (e.g., tensor too large for available memory).
NotImplementedError
Thrown when a feature or code path is not yet implemented.
DataValidationError
Thrown when input data fails validation (e.g., NaN values, empty arrays, invalid config).
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