-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Elixir and Erlang/OTP versions
I believe that for beginners its always good when handling errors does not involve any gotchas.
A common way of how someone coming from other languages might attempt to catch and report an error would be something like this:
try do
result = do_something_complicated()
{:ok, result}
rescue
e ->
Logger.error("Failed to do something", e)
{:error, :db_error}
end
Unfortunately the Logger.error/2 (and all related defs) only accept Maps and List as metadata. So this attempt will just throw it self an (Protocol.UndefinedError) protocol Enumerable not implemented for type RuntimeError (a struct).
error, which can be frustrating.
I believe it would be desirable for the Logger functions to be able to whatever metadata you throw at them, or at least structs. Of course we can use inspect(e) inside the message, but this feels like unneeded boilerplate, because to be able to pass some kind of context information into an error is a very common thing.
Operating system
Linux
Current behavior
(Protocol.UndefinedError) protocol Enumerable not implemented for type RuntimeError (a struct).
Expected behavior
s.a.