Ply.Error exception (Ply v0.1.0)

Copy Markdown View Source

Describes a failure to read or write a PLY file.

Errors carry the byte offset where the problem was found, plus the element, row, and property when known. On a gigabyte file, knowing a float was malformed at byte 900,000,000 in row 3,600,000 of vertex is the difference between a fixable report and a shrug.

This struct is also an exception, so the same value can be returned from Ply.read/2 or raised by Ply.read!/2.

Summary

Types

What went wrong

t()

Functions

Builds an error.

Types

kind()

@type kind() ::
  :not_ply
  | :bad_header
  | :unknown_type
  | :unsupported_format
  | :truncated
  | :bad_value
  | :invalid_list_count
  | :variable_width
  | :no_such_element
  | :no_such_property
  | :count_mismatch
  | :trailing_data
  | :io_error

What went wrong:

  • :not_ply — the file does not begin with the PLY magic number
  • :bad_header — the header is malformed or contains an unknown directive
  • :unknown_type — a property declares a type name we do not recognise
  • :unsupported_format — the format line is not one of the three PLY formats
  • :truncated — the data ends before the declared counts are satisfied
  • :bad_value — a value could not be decoded (malformed ASCII number, …)
  • :invalid_list_count — a list length exceeds the bytes remaining
  • :variable_width — an operation requiring fixed-width rows hit a list property
  • :no_such_element — the requested element is not present in the file
  • :no_such_property — the requested property is not present in the element
  • :count_mismatch — supplied rows disagree with the count the header declares
  • :trailing_data — data remains after every declared element was read
  • :io_error — the file could not be opened or read

t()

@type t() :: %Ply.Error{
  __exception__: true,
  detail: String.t() | nil,
  element: String.t() | nil,
  kind: kind(),
  offset: non_neg_integer() | nil,
  property: String.t() | nil,
  row: non_neg_integer() | nil
}

Functions

new(kind, opts \\ [])

@spec new(
  kind(),
  keyword()
) :: t()

Builds an error.

iex> Ply.Error.new(:truncated, offset: 512) |> Map.take([:kind, :offset])
%{kind: :truncated, offset: 512}