Skip to content

Commit e18d517

Browse files
committed
fix: handle nil errors or invalid errors
1 parent 66e4e90 commit e18d517

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

lib/ash_appsignal.ex

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,15 @@ defmodule AshAppsignal do
8080
end
8181

8282
try do
83-
error =
84-
error
85-
|> Ash.Error.to_error_class()
86-
|> case do
87-
%Ash.Error.Unknown{} = unknown -> unknown
88-
%{errors: [error]} -> error
89-
error -> error
90-
end
83+
reported_error = normalize_error(error)
9184

9285
stacktrace =
93-
case error do
86+
case reported_error do
9487
%{stacktrace: %{stacktrace: stacktrace}} -> stacktrace
9588
_other -> opts[:stacktrace]
9689
end
9790

98-
Appsignal.Span.add_error(current_appsignal_span(), error, stacktrace)
91+
Appsignal.Span.add_error(current_appsignal_span(), reported_error, stacktrace)
9992
after
10093
if needs_span? do
10194
stop_span()
@@ -105,6 +98,21 @@ defmodule AshAppsignal do
10598
:ok
10699
end
107100

101+
defp normalize_error(nil) do
102+
nil
103+
end
104+
105+
defp normalize_error(error) do
106+
case Ash.Error.to_error_class(error) do
107+
%Ash.Error.Unknown{} = unknown -> unknown
108+
%{errors: [single]} -> single
109+
other -> other
110+
end
111+
rescue
112+
_coercion_error ->
113+
error
114+
end
115+
108116
defp current_appsignal_span do
109117
Appsignal.Tracer.current_span() || Process.get(:parent_appsignal_span)
110118
end

0 commit comments

Comments
 (0)