Packages

EPUB read and write for Elixir, backed by a Rustler NIF.

Current section

Files

Jump to
langelic_epub lib langelic_epub error.ex
Raw

lib/langelic_epub/error.ex

defmodule LangelicEpub.Error do
@moduledoc """
Error returned from `LangelicEpub.parse/1` or `LangelicEpub.build/1`.
The `kind` field is an atom identifying the error class. The `message` field
is a human-readable string suitable for logging.
## Kinds
Parse errors:
* `:invalid_zip` — bytes are not a valid ZIP archive
* `:invalid_mimetype` — `mimetype` entry is missing or its content is not
`application/epub+zip` (a leading UTF-8 BOM and surrounding whitespace
are tolerated)
* `:missing_container` — no `META-INF/container.xml`
* `:missing_opf` — OPF file referenced in container.xml not found
* `:malformed_opf` — OPF could not be parsed
* `:io` — internal I/O failure
Build errors:
* `:missing_required_field` — title, identifier, or language is missing
* `:invalid_chapter` — a chapter's data is not valid UTF-8 XHTML
* `:duplicate_id` — two chapters or assets share the same `id`
* `:invalid_page_direction` — `page_progression_direction` is not `"rtl"`,
`"ltr"`, or `nil`
Safety:
* `:panic` — Rust side panicked. This should never happen — report a bug.
"""
@type kind ::
:invalid_zip
| :invalid_mimetype
| :missing_container
| :missing_opf
| :malformed_opf
| :io
| :missing_required_field
| :invalid_chapter
| :duplicate_id
| :invalid_page_direction
| :panic
@type t :: %__MODULE__{kind: kind(), message: String.t()}
defexception [:kind, :message]
@impl true
def message(%__MODULE__{message: m}), do: m
end