@@ -18,11 +18,11 @@ defmodule Zexbox.AutoEscalation do
1818 rescue
1919 e ->
2020 Zexbox.AutoEscalation.handle_error(
21- error: e,
21+ e,
22+ "checkout",
23+ "High",
24+ "Purchase Ops",
2225 stacktrace: __STACKTRACE__,
23- action: "checkout",
24- priority: "High",
25- zigl_team: "Purchase Ops",
2626 user_context: %{email: user.email},
2727 additional_context: %{basket_id: basket.id}
2828 )
@@ -74,11 +74,11 @@ defmodule Zexbox.AutoEscalation do
7474 @ doc """
7575 Handle an error by finding or creating a Jira ticket.
7676
77- Required options :
78- - `: error` – the `Exception.t()` that was rescued.
79- - `: action` – short label (e.g. `"checkout"`); used in the fingerprint and summary.
80- - `: priority` – Jira priority name (e.g. `"High"`).
81- - `: zigl_team` – value for the ZIGL Team custom field.
77+ Required arguments :
78+ - `error` – the `Exception.t()` that was rescued.
79+ - `action` – short label (e.g. `"checkout"`); used in the fingerprint and summary.
80+ - `priority` – Jira priority name (e.g. `"High"`).
81+ - `zigl_team` – value for the ZIGL Team custom field.
8282
8383 Optional options:
8484 - `:stacktrace` – pass `__STACKTRACE__` from the rescue block for a full trace.
@@ -87,10 +87,11 @@ defmodule Zexbox.AutoEscalation do
8787 - `:fingerprint` – override deduplication key; defaults to `"action::ErrorClass"`.
8888 - `:custom_description` – string rendered above Error Details (split on `\\ n\\ n`).
8989 """
90- @ spec handle_error ( keyword ( ) ) :: { :ok , map ( ) } | { :error , term ( ) } | { :disabled , nil }
91- def handle_error ( opts ) do
90+ @ spec handle_error ( Exception . t ( ) , String . t ( ) , String . t ( ) , String . t ( ) , keyword ( ) ) ::
91+ { :ok , map ( ) } | { :error , term ( ) } | { :disabled , nil }
92+ def handle_error ( error , action , priority , zigl_team , opts \\ [ ] ) do
9293 if auto_escalation_enabled? ( ) do
93- do_handle_error ( opts )
94+ do_handle_error ( error , action , priority , zigl_team , opts )
9495 else
9596 { :disabled , nil }
9697 end
@@ -101,28 +102,19 @@ defmodule Zexbox.AutoEscalation do
101102
102103 ## Examples
103104
104- iex> Zexbox.AutoEscalation.generate_fingerprint(error_class: "StandardError", action: "checkout")
105+ iex> Zexbox.AutoEscalation.generate_fingerprint("StandardError", "checkout")
105106 "checkout::StandardError"
106107 """
107- @ spec generate_fingerprint ( keyword ( ) ) :: String . t ( )
108- def generate_fingerprint ( opts ) do
109- error_class = Keyword . fetch! ( opts , :error_class )
110- action = Keyword . fetch! ( opts , :action )
111- "#{ action } ::#{ error_class } "
112- end
108+ @ spec generate_fingerprint ( String . t ( ) , String . t ( ) ) :: String . t ( )
109+ def generate_fingerprint ( error_class , action ) , do: "#{ action } ::#{ error_class } "
113110
114111 # --- Private ---
115112
116- defp do_handle_error ( opts ) do
117- error = Keyword . fetch! ( opts , :error )
118-
113+ defp do_handle_error ( error , action , priority , zigl_team , opts ) do
119114 unless is_exception ( error ) do
120115 raise ArgumentError , "Expected an Exception.t() for :error, got: #{ inspect ( error ) } "
121116 end
122117
123- action = Keyword . fetch! ( opts , :action )
124- priority = Keyword . fetch! ( opts , :priority )
125- zigl_team = Keyword . fetch! ( opts , :zigl_team )
126118 user_context = Keyword . get ( opts , :user_context , % { } )
127119 additional_context = Keyword . get ( opts , :additional_context , % { } )
128120 stacktrace = Keyword . get ( opts , :stacktrace )
@@ -132,31 +124,31 @@ defmodule Zexbox.AutoEscalation do
132124
133125 fingerprint =
134126 Keyword . get ( opts , :fingerprint ) ||
135- generate_fingerprint ( error_class: error_class , action: action )
127+ generate_fingerprint ( error_class , action )
136128
137129 case find_existing_ticket ( fingerprint ) do
138130 nil ->
139131 create_jira_ticket (
140- error: error ,
141- action: action ,
142- priority: priority ,
143- zigl_team: zigl_team ,
144- fingerprint: fingerprint ,
145- user_context: user_context ,
146- additional_context: additional_context ,
147- custom_description: custom_description ,
148- stacktrace: stacktrace
132+ error ,
133+ action ,
134+ priority ,
135+ zigl_team ,
136+ fingerprint ,
137+ user_context ,
138+ additional_context ,
139+ custom_description ,
140+ stacktrace
149141 )
150142
151143 existing_ticket ->
152144 add_comment_to_existing_ticket (
153- ticket: existing_ticket ,
154- error: error ,
155- action: action ,
156- user_context: user_context ,
157- additional_context: additional_context ,
158- custom_description: custom_description ,
159- stacktrace: stacktrace
145+ existing_ticket ,
146+ error ,
147+ action ,
148+ user_context ,
149+ additional_context ,
150+ custom_description ,
151+ stacktrace
160152 )
161153
162154 { :ok , existing_ticket }
@@ -170,7 +162,7 @@ defmodule Zexbox.AutoEscalation do
170162 status_list = Enum . map_join ( @ resolved_statuses , ", " , fn s -> "\" #{ s } \" " end )
171163 jql = "\" #{ field_name } \" = \" #{ escaped } \" AND status NOT IN (#{ status_list } )"
172164
173- case JiraClient . search_latest_issues ( jql: jql , project_key: project_key ) do
165+ case JiraClient . search_latest_issues ( jql , project_key ) do
174166 { :ok , [ ] } ->
175167 nil
176168
@@ -186,17 +178,17 @@ defmodule Zexbox.AutoEscalation do
186178 end
187179 end
188180
189- defp create_jira_ticket ( opts ) do
190- error = Keyword . fetch! ( opts , : error)
191- action = Keyword . fetch! ( opts , : action)
192- priority = Keyword . fetch! ( opts , : priority)
193- zigl_team = Keyword . fetch! ( opts , : zigl_team)
194- fingerprint = Keyword . fetch! ( opts , : fingerprint)
195- user_context = Keyword . fetch! ( opts , : user_context)
196- additional_context = Keyword . fetch! ( opts , : additional_context)
197- custom_description = Keyword . get ( opts , : custom_description)
198- stacktrace = Keyword . get ( opts , : stacktrace)
199-
181+ defp create_jira_ticket (
182+ error ,
183+ action ,
184+ priority ,
185+ zigl_team ,
186+ fingerprint ,
187+ user_context ,
188+ additional_context ,
189+ custom_description ,
190+ stacktrace
191+ ) do
200192 project_key = resolve_project_key ( )
201193 error_class = inspect ( error . __struct__ )
202194
@@ -216,15 +208,14 @@ defmodule Zexbox.AutoEscalation do
216208
217209 with { :ok , result } <-
218210 JiraClient . create_issue (
219- project_key: project_key ,
220- summary: "#{ action } : #{ error_class } " ,
221- description: description ,
222- issuetype: @ issuetype ,
223- priority: priority ,
224- custom_fields: custom_fields
211+ project_key ,
212+ "#{ action } : #{ error_class } " ,
213+ description ,
214+ @ issuetype ,
215+ priority ,
216+ custom_fields
225217 ) ,
226- { :ok , _ } <-
227- JiraClient . transition_issue ( issue_key: result [ "key" ] , status_name: @ transition_to ) do
218+ { :ok , _ } <- JiraClient . transition_issue ( result [ "key" ] , @ transition_to ) do
228219 { :ok , result }
229220 else
230221 { :error , e } ->
@@ -236,15 +227,15 @@ defmodule Zexbox.AutoEscalation do
236227 end
237228 end
238229
239- defp add_comment_to_existing_ticket ( opts ) do
240- ticket = Keyword . fetch! ( opts , : ticket)
241- error = Keyword . fetch! ( opts , : error)
242- action = Keyword . fetch! ( opts , : action)
243- user_context = Keyword . fetch! ( opts , : user_context)
244- additional_context = Keyword . fetch! ( opts , : additional_context)
245- custom_description = Keyword . get ( opts , : custom_description)
246- stacktrace = Keyword . get ( opts , : stacktrace)
247-
230+ defp add_comment_to_existing_ticket (
231+ ticket ,
232+ error ,
233+ action ,
234+ user_context ,
235+ additional_context ,
236+ custom_description ,
237+ stacktrace
238+ ) do
248239 issue_key = ticket [ "key" ]
249240
250241 comment =
@@ -257,7 +248,7 @@ defmodule Zexbox.AutoEscalation do
257248 stacktrace: stacktrace
258249 )
259250
260- case JiraClient . add_comment ( issue_key: issue_key , comment: comment ) do
251+ case JiraClient . add_comment ( issue_key , comment ) do
261252 { :ok , _ } ->
262253 :ok
263254
0 commit comments