Meeseeks.Error
Prior to v0.9.0, errors in Meeseeks were all over the place- sometimes they returned {:error, string}
or :error
, sometimes they raised RuntimeError
s or ArgumentError
s or one of an assortment of custom Meeseeks exceptions.
To combat this, I have added a Meeseeks.Error
struct that implements the Exception
behaviour and used it throughout the library.
I go into more details about the rationale and implementation in this issue, but the quick takeaway is that this kind of error struct is flexible, plays nicely with pattern matching in places like case
and with
, and makes it easier to provide useful errors to users.
This is a breaking change because it modifies the returned or raised type of errors. If your Meeseeks-related code handles {:error, ???}
or catches one of the old Meeseeks exception types, you will need to make changes.
I apologize for the inconvenience, but this change should lead to safer, more friendly code in the future.
Meeseeks.fetch_all
and Meeseeks.fetch_one
The more that I use Elixir in anger, the more I appreciate functions that return {:ok, ...}
or {:error, ...}
.
In light of the feedback I received on this issue I decided to add Meeseeks.fetch_all
and Meeseeks.fetch_one
which work like Meeseeks.all
and Meeseeks.one
respectively, but wrap the result in {:ok, ...}
if there is a match or return {:error, %Meeseeks.Error{type: :select, reason: :no_match}}
if there is not.
Now itās easier to write code like:
with({:ok, qt} <- Meeseeks.fetch_one(doc, css(".qt"))) do
...
else
{:error, %Meeseeks.Error{type: :select, reason: :no_match}} ->
...
end
My thanks to those who provided feedback.
Other
A bug related to Meeseeks.html
was fixed, see this issue for more details