ExMaude.Error exception (ExMaude v0.3.0)

View Source

Structured error types for ExMaude operations.

This module provides rich error representations that make it easier to handle and display Maude errors in Elixir applications.

Error Types

  • :parse_error - Failed to parse a term
  • :module_not_found - Referenced module doesn't exist
  • :syntax_error - Invalid Maude syntax
  • :timeout - Operation timed out
  • :busy - Worker already has a command in flight
  • :maude_crash - Maude process crashed
  • :file_not_found - File doesn't exist
  • :load_error - Failed to load a module
  • :pool_error - Pool checkout/operation failed
  • :invalid_path - Path validation failed
  • :ambiguous_term - Term has multiple parses
  • :sort_error - Sort/type mismatch
  • :not_connected - Backend not connected (C-Node)
  • :cnode_error - C-Node communication error
  • :nif_not_loaded - NIF binary failed to load (precompiled binary missing for the host platform; set EX_MAUDE_BUILD=1 to build from source, or check that your platform is in the supported targets list)
  • :nif_error - Runtime error from the NIF backend
  • :validation - Input validation failed
  • :unknown - Unrecognized error

Usage

case ExMaude.reduce("NAT", "invalid syntax $$") do
  {:ok, result} -> handle_result(result)
  {:error, %ExMaude.Error{type: :parse_error, message: msg}} ->
    Logger.warning("Parse error: #{msg}")
end

Creating Errors

# From Maude output
error = ExMaude.Error.from_output("Warning: module NAT not found")

# Directly
error = ExMaude.Error.new(:timeout, "Operation exceeded 5000ms")

Summary

Functions

Creates a Maude crash error.

Creates a new error with the given type and message.

Creates a file not found error.

Creates an error from Maude output by detecting the error type.

Creates an invalid path error for security violations.

Creates a new error with the given type and message.

Creates a partial load error when some modules fail to load.

Creates a pool error when pool operations fail.

Checks if the error is recoverable.

Creates a timeout error.

Converts the error to a simple tuple format for pattern matching.

Types

error_type()

@type error_type() ::
  :parse_error
  | :module_not_found
  | :syntax_error
  | :timeout
  | :busy
  | :maude_crash
  | :file_not_found
  | :load_error
  | :pool_error
  | :invalid_path
  | :ambiguous_term
  | :sort_error
  | :not_connected
  | :cnode_error
  | :nif_not_loaded
  | :nif_error
  | :validation
  | :unknown

t()

@type t() :: %ExMaude.Error{
  __exception__: true,
  details: map() | nil,
  message: String.t(),
  raw_output: String.t() | nil,
  type: error_type()
}

Functions

crash(exit_code)

@spec crash(integer()) :: t()

Creates a Maude crash error.

Examples

iex> error = ExMaude.Error.crash(137)
...> {error.type, error.message}
{:maude_crash, "Maude process crashed with exit code 137"}

exception(type, message)

@spec exception(error_type(), String.t()) :: t()

Creates a new error with the given type and message.

Alias for new/2 for convenience.

Examples

iex> error = ExMaude.Error.exception(:not_connected, "C-Node not connected")
...> {error.type, error.message}
{:not_connected, "C-Node not connected"}

file_not_found(path)

@spec file_not_found(Path.t()) :: t()

Creates a file not found error.

Examples

iex> error = ExMaude.Error.file_not_found("/path/to/missing.maude")
...> {error.type, error.message}
{:file_not_found, "File not found: /path/to/missing.maude"}

from_output(output)

@spec from_output(String.t()) :: t()

Creates an error from Maude output by detecting the error type.

Parses the output to identify the type of error and extract a meaningful message.

Examples

iex> error = ExMaude.Error.from_output("Warning: module FOO not found")
...> {error.type, error.message}
{:module_not_found, "Module not found: FOO"}

invalid_path(reason)

@spec invalid_path(String.t()) :: t()

Creates an invalid path error for security violations.

Examples

iex> error = ExMaude.Error.invalid_path("Path escapes temp directory")
...> {error.type, error.message}
{:invalid_path, "Path escapes temp directory"}

new(type, message, opts \\ [])

@spec new(error_type(), String.t(), keyword()) :: t()

Creates a new error with the given type and message.

Examples

iex> error = ExMaude.Error.new(:timeout, "Operation timed out")
...> {error.type, error.message}
{:timeout, "Operation timed out"}

partial_load(failures)

@spec partial_load([term()]) :: t()

Creates a partial load error when some modules fail to load.

Examples

iex> error = ExMaude.Error.partial_load([{:error, "syntax error"}])
...> {error.type, error.message}
{:load_error, "Partial load: 1 module(s) failed to load"}

pool_error(reason)

@spec pool_error(term()) :: t()

Creates a pool error when pool operations fail.

Examples

iex> error = ExMaude.Error.pool_error(:timeout)
...> {error.type, error.message}
{:pool_error, "Pool checkout timed out"}

recoverable?(error)

@spec recoverable?(t()) :: boolean()

Checks if the error is recoverable.

Some errors like timeouts might be recoverable by retrying, while others like syntax errors are not.

timeout(timeout_ms)

@spec timeout(non_neg_integer()) :: t()

Creates a timeout error.

Examples

iex> error = ExMaude.Error.timeout(5000)
...> {error.type, error.message}
{:timeout, "Operation timed out after 5000ms"}

to_tuple(error)

@spec to_tuple(t()) :: {error_type(), String.t()}

Converts the error to a simple tuple format for pattern matching.

Examples

iex> error = ExMaude.Error.new(:timeout, "timed out")
...> ExMaude.Error.to_tuple(error)
{:timeout, "timed out"}