Spectral.Error exception (Spectral v0.13.0)

View Source

Exception for Spectral operations.

This exception represents errors returned from the underlying :spectra library, converted to an idiomatic Elixir format.

Can be used both in {:error, [%Spectral.Error{}]} tuples and raised as an exception.

Fields

  • :location - Path to where the error occurred (list of strings or atoms)
  • :type - Type of error (:decode_error, :type_mismatch, :no_match, :missing_data, :not_matched_fields)
  • :context - Additional context information about the error (runtime-determined type)
  • :message - Human-readable error message (auto-generated for exceptions)

Example

%Spectral.Error{
  location: ["user", "age"],
  type: :type_mismatch,
  context: %{expected: :integer, got: "not a number"}
}

Summary

Types

error_type()

@type error_type() ::
  :decode_error
  | :type_mismatch
  | :no_match
  | :missing_data
  | :not_matched_fields

t()

@type t() :: %Spectral.Error{
  __exception__: true,
  context: dynamic(),
  location: [String.t() | atom()],
  message: String.t() | nil,
  type: error_type()
}