Hello!
I'm wrapping an Erlang library with relatively descriptive errors. Still
want them to be nicely repackaged into Elixir Exceptions.
However it looks like there is no way to convert custom errors without
loosing stack. Basically I have to catch/reraise.
In other words ErlangError.normalize isn't extendable now
(https://github.com/elixir-lang/elixir/blob/acbf7cab01ad4811e86ecff4312e2616fc01030f/lib/elixir/lib/exception.ex#L890).
I think it'd be cool to be able to easily 'marshal' errors. I'm not sure I
can suggest acceptable implementation but I was thinking about
special behavior 'ErlangError' with normalize_error/2 callback so
ErlangError.normalize can search stacktrace for nearest module that
implements it and call normalize_error/2.
defmodule Prometheus.Metric.Counter do
> @behavior ErlangError
>
> def normalize_error({:invalid_value, value, message},_stacktrace) do
> %Prometheus.Error.InvalidValue{value: value, omessage: message}
> end
>
> def inc(spec, value \\ 1) do
> :prometheus_counter.inc(spec, value)
> end
> end
>
> Counter.inc([name, :http_requests_total], "string")
> ** (Prometheus.Error.InvalidValue) got 'inc accepts only integers'
>
Or maybe via configuration? What you think?
Ilya.
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/c8a002eb-665c-455a-ba9a-fe9fe44bfe14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.