zachdaniel

zachdaniel

Creator of Ash

Splode - Aggregatable and consistent errors for Elixir

Announcing splode, a tiny library for creating aggregatable and consistent errors for Elixir. Splode is useful for situations when multiple things can go wrong with a given process and you want to combine them into a reasonable response, or when you want consistency in the way you handle errors.

Benefits of using Splode:

  • Errors are regular exceptions. They can be raised, but they can also be combined into an “error class”.
  • Creating a new splode exception captures the stacktrace where it was created. This is extremely useful for situations where you want to illustrate multiple errors.
  • Splode comes with tools to turn arbitrary values into exceptions, and standardizes on a few useful things, like attaching bread_crumbs to errors, storing a path for when errors occur inside of a data structure, and using field and fields for when errors correspond to a field or fields at said path. These conventions allow for writing consistent error handling code across your application.

It is lightly documented at the moment, as its primary reason for existing is to share Ash’s error patterns between Ash and Reactor, and any other packages that we introduce further on down the line.

This is a tiny library that may only be useful in certain situations or for folks who like this pattern, but it is an example of what we’re looking to do with Ash Framework as much as possible going forward, which is to contribute back to the general Elixir ecosystem as much as possible. We want the Elixir ecosystem at large to be able to benefit from our work, regardless of whether or not folks are using Ash :slight_smile:

Check out the getting started guide for more! Get Started with Splode — splode v0.1.1

Most Liked

zachdaniel

zachdaniel

Creator of Ash

I’ve made the following changes in 0.2.0:

  1. now you define message/1 instead of splode_message/1
  2. use Splode.ErrorClass can be used now, which adds the errors field and a default message/1 implementation.

As for the other things discussed:

  1. deriving error class from namespaces: I’d personally rather not do this. It takes something explicit and makes it implicit. I imagine users that want to do this can create a custom module to use and make it work that way for them.

  2. adding a default message/1 for any given error. I’m open to this, I just didn’t get around to it. It wouldn’t be a breaking change, so PRs welcome on that front :slight_smile:

zachallaun

zachallaun

If you were to switch from splode_message to using message, I think you’d need to use @before_compile and defoverridable message: 1. A basic sketch:

defmodule Splode.Error do
  defmacro __using__(opts) do
    quote do
      @before_compile unquote(__MODULE__)
      # mostly everything as before, except don't def message here
    end
  end

  defmacro __before_compile__(env) do
    ensure_def_message =
      if Module.defines?(env, {:message, 1}, :def) do
        quote(do: defoverridable message: 1)
      else
        quote do
          # default impl
        end
      end

    quote do
      unquote(ensure_def_message)

      # the existing def message implementation, except use super instead of calling splode_message
      def message(%{vars: vars} = exception) do
        string = super(exception)
        ...
      end
    end
  end
end
zachallaun

zachallaun

I’d like to contribute, but won’t likely have time until mid next week at the earliest. If you want to get to it before then, that’s perfectly fine by me! How about this: I’ll open issues for these suggestions, and whichever of us gets started first can reply to those so that we’re not duplicating effort. :slight_smile:

Where Next?

Popular in Libraries Top

Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 13801 100
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
zoltanszogyenyi
Hey everyone :wave: Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-source U...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
gjaldon
As the title states, EctoEnum has just been updated after some time of hardly any activity in the repo. Here’s the latest release: https:...
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

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Sub Categories:

We're in Beta

About us Mission Statement