jvoegele

jvoegele

Errata - Structured error handling for Elixir

Announcing Errata, an Elixir library for consistent and structured error handling.

Errata is an Elixir library that promotes a consistent and structured approach to error handling.

Errata provides support for defining custom structured error types, which can either be returned as error values or raised as exceptions.

Errata errors are named, structured types that represent error conditions in an application or library. Being named types means that errors have a unique and meaningful name within a particular context. Being structured types means that errors have a well-defined, consistent structure identifying the nature of the error, and can also have arbitrary contextual information attached to them for logging or debugging purposes.

Most Liked Responses

jvoegele

jvoegele

Errata 0.9.0 is out, and it’s a sizable release — some new conveniences, sharper defaults, and a thorough documentation overhaul.

New functions

  • Errata.create/2 — create an error of any type while still capturing the call-site environment, without having to require each error module. Since you already require Errata to use the guards, you can just alias your error modules and write:

    require Errata
    alias MyApp.Orders.OrderNotFound
    
    Errata.create(OrderNotFound, reason: :not_found, context: %{order_id: id})
    
  • Errata.to_map/1 — convert any Errata error to a plain, JSON-encodable map without needing to know its specific module. Handy at a system boundary (e.g. a Phoenix fallback controller) that handles many error types uniformly.

  • Errata.display_message/1 — the bare, human-readable message intended for end users, as distinct from Exception.message/1, which combines the message and :reason for logs and raised-exception output.

Sharper defaults

  • Creating an error with an unrecognized or misspelled key (say, reasn: instead of reason:) now raises an ArgumentError instead of silently dropping it. :warning: This is the one breaking change in 0.9.0 — see Upgrading below.

Fixes

  • Serialized errors are cleaner: JSON output no longer leaks the Elixir. prefix on module names, and env.file_line no longer has a stray trailing colon.

Docs & tooling

  • The guide has been reorganized around a single running example (an Orders bounded context), with clearer guidance on choosing between domain, infrastructure, and general errors, and on when to use a distinct error type vs. a :reason.
  • There’s now a CI pipeline that runs the test suite across Elixir 1.15–1.18 and OTP 25–27, plus formatting, Credo, Dialyzer, and docs checks.

Upgrading

Bump your dependency to:

{:errata, "~> 0.9.0"}

The only breaking change is the stricter param validation. If you were (perhaps unknowingly) relying on extra keys being ignored, you’ll now get a clear ArgumentError — in practice this usually just surfaces a typo.

Thanks to everyone who’s given Errata a try and shared feedback; it’s genuinely shaped this release. More is always welcome.

jvoegele

jvoegele

Quick update for anyone following along: Errata has reached 1.0.0 — its first stable, production-ready release, with the public API now covered by Semantic Versioning. :tada:

Since this thread it has grown a fair bit: error wrapping/chaining (a :cause field), context enrichment as errors propagate, declared-and-validated :reasons, error reporting via structured logging and telemetry, and HTTP-status mapping by error kind — alongside a thorough documentation pass.

I’ve written up the full 1.0.0 picture, with examples, in a dedicated thread:

Thanks to everyone who’s tried Errata and shared feedback — it genuinely shaped the road to 1.0.

jvoegele

jvoegele

Hi @nathanl,

The create/1 macro uses Process.info(self(), :current_stacktrace) to fill in the stacktrace. I’m not sure about the efficiency of this function, but I would venture to say that if you are using create/1 for creating Errata errors in your codebase then it would probably not be on the critical path and would not affect overall system performance to any appreciable degree.

Where Next?

Popular in Announcing Top

martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19228 141
New
Qqwy
Today I realized that it would be possible to implement currying-capability in Elixir, using some clever anonymous function creation. (‘c...
New
kip
ex_cldr provides localisation and internationalisation support based upon the data from the Unicode CLDR project. Unicode released CLDR ...
407 12840 120
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
New
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement