DprintMarkdownFormatter.Error (dprint_markdown_formatter v0.3.0)

View Source

Error utilities for DprintMarkdownFormatter.

This module provides validation errors and helper functions for creating standard Elixir exceptions with descriptive messages.

Summary

Functions

Creates an argument error for configuration issues.

Creates a runtime error for formatting failures.

Creates a runtime error for NIF failures.

Creates a runtime error for parsing failures.

Creates a validation error.

Types

Functions

config_error(message, opts \\ [])

@spec config_error(
  String.t(),
  keyword()
) :: Exception.t()

Creates an argument error for configuration issues.

format_error(message, opts \\ [])

@spec format_error(
  String.t(),
  keyword()
) :: Exception.t()

Creates a runtime error for formatting failures.

nif_error(message, opts \\ [])

@spec nif_error(
  String.t(),
  keyword()
) :: Exception.t()

Creates a runtime error for NIF failures.

Used when the Rust NIF returns an error during markdown formatting.

Examples

iex> DprintMarkdownFormatter.Error.nif_error("NIF formatting failed")
%RuntimeError{message: "NIF formatting failed"}

iex> DprintMarkdownFormatter.Error.nif_error("NIF error", original_error: "Invalid markdown syntax")
%RuntimeError{message: "NIF error: Invalid markdown syntax"}

parse_error(message, opts \\ [])

@spec parse_error(
  String.t(),
  keyword()
) :: Exception.t()

Creates a runtime error for parsing failures.

Used when Elixir code parsing fails, such as when processing module attributes.

Examples

iex> DprintMarkdownFormatter.Error.parse_error("Failed to parse code")
%RuntimeError{message: "Failed to parse code"}

iex> original_error = %SyntaxError{message: "unexpected token"}
iex> DprintMarkdownFormatter.Error.parse_error("Parse failed", original_error: original_error)
%RuntimeError{message: "Parse failed: %SyntaxError{message: \"unexpected token\"}"}

validation_error(message, opts \\ [])

Creates a validation error.