[Proposal][Feature request] Extendable ErlangError.normalize

27 views
Skip to first unread message

dead.tr...@gmail.com

unread,
Aug 24, 2016, 5:20:21 PM8/24/16
to elixir-lang-core
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.

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.
Reply all
Reply to author
Forward
0 new messages