ExMaude. Error exception
(ExMaude v0.2.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: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; setEX_MAUDE_BUILD=1to 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}")
endCreating 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
@type error_type() ::
:parse_error
| :module_not_found
| :syntax_error
| :timeout
| :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
@type t() :: %ExMaude.Error{ __exception__: true, details: map() | nil, message: String.t(), raw_output: String.t() | nil, type: error_type() }
Functions
Creates a Maude crash error.
Examples
error = ExMaude.Error.crash(137)
error.type #=> :maude_crash
@spec exception(error_type(), String.t()) :: t()
Creates a new error with the given type and message.
Alias for new/2 for convenience.
Examples
error = ExMaude.Error.exception(:not_connected, "C-Node not connected")
error.type #=> :not_connected
error.message #=> "C-Node not connected"
Creates a file not found error.
Examples
error = ExMaude.Error.file_not_found("/path/to/missing.maude")
error.type #=> :file_not_found
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
error = ExMaude.Error.from_output("Warning: module FOO not found")
error.type #=> :module_not_found
error.message #=> "module FOO not found"
Creates an invalid path error for security violations.
Examples
error = ExMaude.Error.invalid_path("Path escapes temp directory")
error.type #=> :invalid_path
@spec new(error_type(), String.t(), keyword()) :: t()
Creates a new error with the given type and message.
Examples
error = ExMaude.Error.new(:timeout, "Operation timed out")
error.type #=> :timeout
error.message #=> "Operation timed out"
Creates a partial load error when some modules fail to load.
Examples
error = ExMaude.Error.partial_load([{:error, "syntax error"}])
error.type #=> :load_error
Creates a pool error when pool operations fail.
Examples
error = ExMaude.Error.pool_error(:timeout)
error.type #=> :pool_error
Checks if the error is recoverable.
Some errors like timeouts might be recoverable by retrying, while others like syntax errors are not.
@spec timeout(non_neg_integer()) :: t()
Creates a timeout error.
Examples
error = ExMaude.Error.timeout(5000)
error.type #=> :timeout
error.message #=> "Operation timed out after 5000ms"
@spec to_tuple(t()) :: {error_type(), String.t()}
Converts the error to a simple tuple format for pattern matching.
Examples
error = ExMaude.Error.new(:timeout, "timed out")
ExMaude.Error.to_tuple(error) #=> {:timeout, "timed out"}