Snakepit.Error.Parser (Snakepit v0.8.7)

View Source

Parses Python exception data into structured Elixir errors.

Automatically detects error patterns (OOM, shape mismatch, device errors) and creates appropriate structured exceptions.

Summary

Functions

Extracts a shape from a string representation.

Parses a gRPC error response into a structured error.

Parses error data into a structured error.

Functions

extract_shape(str)

@spec extract_shape(String.t()) :: [integer()] | nil

Extracts a shape from a string representation.

Examples

iex> Parser.extract_shape("[3, 224, 224]")
[3, 224, 224]

iex> Parser.extract_shape("(10, 20)")
[10, 20]

from_grpc_error(arg1)

@spec from_grpc_error(map()) :: {:ok, Exception.t()} | {:error, :invalid_input}

Parses a gRPC error response into a structured error.

parse(data)

@spec parse(map() | term()) :: {:ok, Exception.t()} | {:error, :invalid_input}

Parses error data into a structured error.

Accepts a map with "type", "message", and optionally "traceback".

Examples

{:ok, error} = Parser.parse(%{
  "type" => "ValueError",
  "message" => "Invalid input"
})