I'm struggling with a deprecation warning in my Phoenix app : System.stacktrace/0 outside of rescue/catch clauses is deprecated. If you want to support only Elixir v1.7+, you must access __STACKTRACE__ inside a rescue/catch. If you want to support earlier Elixir versions, move System.stacktrace/0 inside a rescue/catch
.
The thing is, I'm using Rollbax as described in their documentation: Rollbax.report(:error, ArgumentError.exception("oops"), System.stacktrace())
and it feels kind of weird to wrap every case statement I'm doing in a try/rescue block. For example this one:
case (SOME_URL |> HTTPoison.get([], [ ssl: [{:versions, [:'tlsv1.2']}] ])) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
Poison.decode!(body, [keys: :atoms])
{:ok, %HTTPoison.Response{status_code: 404}} ->
Rollbax.report(:error, :not_found, System.stacktrace(), %{reason: "Not found"})
{:ok, %HTTPoison.Response{status_code: 503}} ->
{:error, :ehostunreach}
{:error, %HTTPoison.Error{reason: :ehostunreach}} ->
{:error, :ehostunreach}
{:error, %HTTPoison.Error{reason: :timeout}} ->
Rollbax.report(:error, :timeout, System.stacktrace(), %{reason: :timeout})
{:error, %HTTPoison.Error{reason: reason}} ->
Rollbax.report(:error, :unknown, System.stacktrace(), %{reason: reason})
{:error, reason}
end
I'm not sure how I can have those different report in a single rescue... What would be the proper way to write this one?
__STACKTRACE__ is available only inside catch and rescue clauses of try expressions
. :( Is there any way to use the same kind of pattern matching in the rescue clause so i can have the same behaviour as in my case statement ? – Longshoreman