PhxMediaLibrary.ValidationError exception (PhxMediaLibrary v0.6.1)

Copy Markdown View Source

Exception raised when a media validation fails.

This covers pre-storage validations such as file size limits, MIME type mismatches, content-type verification failures, and collection constraint violations.

Fields

  • :message — human-readable error description
  • :reason — machine-readable atom identifying the validation failure (e.g. :file_too_large, :invalid_mime_type, :content_type_mismatch)
  • :field — the field or aspect that failed validation (e.g. :size, :mime_type)
  • :value — the actual value that was rejected, if available
  • :constraint — the constraint that was violated (e.g. the max size, the accepted MIME types)
  • :metadata — optional map with additional context

Examples

iex> raise PhxMediaLibrary.ValidationError,
...>   message: "file is too large (15 MB, max 10 MB)",
...>   reason: :file_too_large,
...>   field: :size,
...>   value: 15_000_000,
...>   constraint: 10_000_000
** (PhxMediaLibrary.ValidationError) file is too large (15 MB, max 10 MB)

iex> error = %PhxMediaLibrary.ValidationError{
...>   message: "MIME type not accepted",
...>   reason: :invalid_mime_type,
...>   field: :mime_type,
...>   value: "application/exe",
...>   constraint: ["image/jpeg", "image/png"]
...> }
iex> error.reason
:invalid_mime_type

Summary

Types

t()

@type t() :: %PhxMediaLibrary.ValidationError{
  __exception__: true,
  constraint: term(),
  field: atom() | nil,
  message: String.t(),
  metadata: map(),
  reason: atom(),
  value: term()
}