jvoegele

jvoegele

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.

Showing Posts 1 to 5

nathanl

nathanl

This looks interesting! Question: the docs say

Using the create/1 macro, on the other hand, fills in the :env field of the error struct with information from the current __ENV__ struct and the current stacktrace.

I thought that was only available in rescue blocks since System.stacktrace/0 was deprecated years ago - for performance reasons IIRC. Are there any performance implications of using the create/1 macro?

jvoegele

jvoegele OP

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.

nathanl

nathanl

Yeah, hopefully you’re not creating errors in a tight loop. :sweat_smile:

jvoegele

jvoegele OP

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 OP

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.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New

Other Trending Topics Top

mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
lawik
I was thinking since Goatmire Elixir turned out pretty good I should maybe do another one. 30th of Sep - 2nd of Oct this year./ The firs...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews