Delimited.Error exception (Delimited v0.1.0)

Copy Markdown View Source

The single error type returned or raised by every Delimited operation.

Match on :reason. Show Exception.message/1 to a human. The reason is part of the public contract; the message text is not.

The struct carries as much position information as the failing operation knows. A parse failure knows the line; a cast failure also knows the column, the field, and the offending value; a header failure knows neither line nor column. Every position field is therefore nullable, and code that reports errors must tolerate nil.

Summary

Types

Why the operation failed.

t()

Types

reason()

@type reason() ::
  :unterminated_quote
  | :unescaped_quote
  | :missing_header_row
  | :missing_header
  | :duplicate_header
  | :extra_header
  | :row_length_mismatch
  | :cast_failed
  | :required_field_missing
  | :dump_failed
  | :missing_value
  | :io_error

Why the operation failed.

Parsing:

  • :unterminated_quote - a quoted field was still open at the end of input.
  • :unescaped_quote - a character followed a closing quote where only a delimiter or a line break is allowed.

Structure:

  • :missing_header_row - the input ended before a header row was read.
  • :missing_header - no column in the header row matches a declared field.
  • :duplicate_header - a column claimed by a field appears more than once.
  • :extra_header - a column is not claimed by any field, and the dialect was read with on_extra_header: :error.
  • :row_length_mismatch - a row holds a different number of cells than the header row, or than the schema declares when reading without headers.

Values:

  • :cast_failed - a cell could not be read as the field's type.
  • :required_field_missing - a field declared required: true had no value.
  • :dump_failed - a value could not be written as the field's type.
  • :missing_value - a row being written holds no key for a field.

Environment:

  • :io_error - the file could not be opened. :detail holds the POSIX reason.

t()

@type t() :: %Delimited.Error{
  __exception__: term(),
  column: pos_integer() | nil,
  detail: term(),
  field: atom() | nil,
  header: String.t() | nil,
  line: pos_integer() | nil,
  path: Path.t() | nil,
  reason: reason(),
  schema: module() | nil,
  value: term()
}