SnakeBridge.ErrorTranslator (SnakeBridge v0.15.0)

Copy Markdown View Source

Translates Python/ML errors into structured SnakeBridge errors.

This module recognizes common ML error patterns from PyTorch, NumPy, and other ML libraries, and translates them into structured error types with actionable suggestions.

Supported Error Types

Examples

iex> error = %RuntimeError{message: "CUDA out of memory"}
iex> SnakeBridge.ErrorTranslator.translate(error)
%SnakeBridge.Error.OutOfMemoryError{device: {:cuda, 0}, ...}

Summary

Functions

Converts a Python/PyTorch dtype string to an Elixir atom.

Translates a Python/ML error to a structured SnakeBridge error.

Translates an error message string to a structured error.

Functions

dtype_from_string(dtype_str)

@spec dtype_from_string(String.t()) :: atom()

Converts a Python/PyTorch dtype string to an Elixir atom.

Examples

iex> SnakeBridge.ErrorTranslator.dtype_from_string("Float")
:float32

iex> SnakeBridge.ErrorTranslator.dtype_from_string("torch.float64")
:float64

translate(error, traceback \\ nil)

@spec translate(Exception.t() | map() | nil, String.t() | nil) :: Exception.t() | nil

Translates a Python/ML error to a structured SnakeBridge error.

Returns the original error if it cannot be translated.

translate_message(message)

@spec translate_message(String.t()) :: Exception.t() | nil

Translates an error message string to a structured error.

Returns nil if the message cannot be translated.