Raxol.CLI.ErrorDisplay (Raxol v2.6.0)

View Source

Enhanced error display for CLI output with intelligent suggestions.

Integrates the ErrorExperience system with terminal output to provide actionable fix suggestions when errors occur in mix tasks.

Usage

# In a mix task
case run_operation() do
  {:ok, result} -> result
  {:error, error} ->
    Raxol.CLI.ErrorDisplay.display_error(error)
    Mix.raise("Operation failed")
end

# With context
Raxol.CLI.ErrorDisplay.display_error(error, %{
  operation: "compilation",
  file: "lib/foo.ex"
})

Summary

Functions

Displays an enhanced error with suggestions.

Displays a simple error without full enhancement.

Wraps an operation and displays enhanced errors if it fails.

Functions

display_error(error, context \\ %{})

@spec display_error(term(), map()) :: :ok

Displays an enhanced error with suggestions.

Takes the raw error and optional context, runs it through ErrorExperience for classification and suggestions, then displays formatted output.

display_simple_error(message, details \\ nil)

@spec display_simple_error(String.t(), String.t() | nil) :: :ok

Displays a simple error without full enhancement.

Use this for simple errors that don't need full ErrorExperience processing.

with_error_handling(operation_name, fun, context \\ %{})

@spec with_error_handling(String.t(), (-> result), map()) ::
  {:ok, result} | {:error, term()}
when result: term()

Wraps an operation and displays enhanced errors if it fails.

Examples

ErrorDisplay.with_error_handling("Compiling project", fn ->
  Mix.Task.run("compile", ["--warnings-as-errors"])
end)