zachdaniel
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
pathfor when errors occur inside of a data structure, and usingfieldandfieldsfor 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 ![]()
Check out the getting started guide for more! Get Started with Splode — splode v0.3.1
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First Post!
zachallaun
Neat! I can think of a few places where this would clean up some of my own code.
A few ergonomics improvements that come to mind:
To ease the transition from existing custom exceptions to Splode and to decrease the API footprint, the existing
messagecallback could be wrapped instead of using asplode_messagecallback.Implement a default
splode_message(ormessageif the first suggestion is taken) that, for instance, just inspects the:fieldspresent in the error.These last two I’m less sure of, but would pretty significantly reduce boilerplate:
Allow module namespaces to be used as implicit error classes when unspecified. For instance:
Define error classes explicitly with
use Splode.ErrorClassas opposed to implicitly by including a:errorsfield. This could inject thesplode_messageimplementation, which it looks like will almost always (or just always?) be the same.Taken all together, before:
And after:
Most Liked
zachdaniel
I’ve made the following changes in
0.2.0:message/1instead ofsplode_message/1use Splode.ErrorClasscan be used now, which adds theerrorsfield and a defaultmessage/1implementation.As for the other things discussed:
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
useand make it work that way for them.adding a default
message/1for 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 frontzachallaun
If you were to switch from
splode_messageto usingmessage, I think you’d need to use@before_compileanddefoverridable message: 1. A basic sketch: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.
Last Post!
zachdaniel
0.2.5adds a.unwrap!/2function on your modules thatuse Splode. This allows defining “bang” versions of your functions more simply.