Skip to content

Commit c2fd173

Browse files
committed
Use Util.inspect_pid/1 on more processes
Whenever possible, have error messages show process labels or names
1 parent e8ad992 commit c2fd173

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

lib/db_connection.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ defmodule DBConnection do
8282
require Logger
8383

8484
alias DBConnection.Holder
85+
alias DBConnection.Util
8586

8687
require Holder
8788

@@ -1357,7 +1358,7 @@ defmodule DBConnection do
13571358
end
13581359

13591360
defp stop(%DBConnection{pool_ref: pool_ref}, kind, reason, stack) do
1360-
msg = "client #{inspect(self())} stopped: " <> Exception.format(kind, reason, stack)
1361+
msg = "client #{Util.inspect_pid(self())} stopped: " <> Exception.format(kind, reason, stack)
13611362
exception = DBConnection.ConnectionError.exception(msg)
13621363
_ = Holder.stop(pool_ref, exception)
13631364
:ok

lib/db_connection/connection.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ defmodule DBConnection.Connection do
100100
[
101101
inspect(mod),
102102
" (",
103-
inspect(self()),
103+
Util.inspect_pid(self()),
104104
") failed to connect: " | Exception.format_banner(:error, err, [])
105105
]
106106
end,
@@ -116,7 +116,7 @@ defmodule DBConnection.Connection do
116116
inspect(mod),
117117
?\s,
118118
?(,
119-
inspect(self()),
119+
Util.inspect_pid(self()),
120120
") failed to connect: "
121121
| Exception.format_banner(:error, err, [])
122122
]
@@ -142,7 +142,7 @@ defmodule DBConnection.Connection do
142142
inspect(mod),
143143
?\s,
144144
?(,
145-
inspect(self()),
145+
Util.inspect_pid(self()),
146146
") disconnected: " | Exception.format_banner(:error, err, [])
147147
]
148148
end)
@@ -343,7 +343,7 @@ defmodule DBConnection.Connection do
343343

344344
def handle_event(:info, msg, :no_state, %{mod: mod} = s) do
345345
Logger.info(fn ->
346-
[inspect(mod), ?\s, ?(, inspect(self()), ") missed message: " | inspect(msg)]
346+
[inspect(mod), ?\s, ?(, Util.inspect_pid(self()), ") missed message: " | inspect(msg)]
347347
end)
348348

349349
handle_timeout(s)

lib/db_connection/holder.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule DBConnection.Holder do
22
@moduledoc false
33
require Record
44

5+
alias DBConnection.Util
6+
57
@queue true
68
@timeout 15000
79
@time_unit 1000
@@ -84,7 +86,7 @@ defmodule DBConnection.Holder do
8486
%{
8587
exception
8688
| message:
87-
"could not checkout the connection owned by #{inspect(caller)}. " <>
89+
"could not checkout the connection owned by #{Util.inspect_pid(caller)}. " <>
8890
"When using the sandbox, connections are shared, so this may imply " <>
8991
"another process is using a connection. Reason: #{message}"
9092
}}
@@ -332,7 +334,7 @@ defmodule DBConnection.Holder do
332334

333335
call_reason =
334336
if maybe_pid do
335-
"Error happened when attempting to transfer to #{inspect(maybe_pid)} " <>
337+
"Error happened when attempting to transfer to #{Util.inspect_pid(maybe_pid)} " <>
336338
"(alive: #{Process.alive?(maybe_pid)})"
337339
else
338340
"Error happened when looking up connection"
@@ -342,7 +344,7 @@ defmodule DBConnection.Holder do
342344
#{inspect(__MODULE__)} #{inspect(holder)} #{reason}, pool inconsistent.
343345
#{call_reason}.
344346
345-
SELF: #{inspect(self())}
347+
SELF: #{Util.inspect_pid(self())}
346348
ETS INFO: #{inspect(:ets.info(holder))}
347349
348350
Please report at https://github.com/elixir-ecto/db_connection/issues"

lib/db_connection/ownership/manager.ex

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ defmodule DBConnection.Ownership.Manager do
262262
if log do
263263
Logger.log(log, fn ->
264264
[
265-
inspect(caller),
265+
Util.inspect_pid(caller),
266266
" checked out connection in ",
267267
inspect(mode),
268268
" mode using proxy ",
269-
inspect(proxy)
269+
Util.inspect_pid(proxy)
270270
]
271271
end)
272272
end
@@ -306,7 +306,13 @@ defmodule DBConnection.Ownership.Manager do
306306
defp owner_allow(%{ets: ets, log: log} = state, caller, allow, ref, proxy) do
307307
if log do
308308
Logger.log(log, fn ->
309-
[inspect(allow), " was allowed by ", inspect(caller), " on proxy ", inspect(proxy)]
309+
[
310+
Util.inspect_pid(allow),
311+
" was allowed by ",
312+
Util.inspect_pid(caller),
313+
" on proxy ",
314+
Util.inspect_pid(proxy)
315+
]
310316
end)
311317
end
312318

@@ -324,7 +330,13 @@ defmodule DBConnection.Ownership.Manager do
324330
defp owner_unallow(%{ets: ets, log: log} = state, caller, unallow, ref, proxy) do
325331
if log do
326332
Logger.log(log, fn ->
327-
[inspect(unallow), " was unallowed by ", inspect(caller), " on proxy ", inspect(proxy)]
333+
[
334+
Util.inspect_pid(unallow),
335+
" was unallowed by ",
336+
Util.inspect_pid(caller),
337+
" on proxy ",
338+
Util.inspect_pid(proxy)
339+
]
328340
end)
329341
end
330342

@@ -348,9 +360,9 @@ defmodule DBConnection.Ownership.Manager do
348360
if log do
349361
Logger.log(log, fn ->
350362
[
351-
Enum.map_join(entries, ", ", &inspect/1),
363+
Enum.map_join(entries, ", ", &Util.inspect_pid/1),
352364
" lost connection from proxy ",
353-
inspect(proxy)
365+
Util.inspect_pid(proxy)
354366
]
355367
end)
356368
end

lib/db_connection/ownership/proxy.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ defmodule DBConnection.Ownership.Proxy do
158158

159159
@impl true
160160
def handle_cast({:stop, caller}, %{owner: {owner, _}} = state) do
161-
message = "#{inspect(caller)} checked in the connection owned by #{inspect(owner)}"
161+
message =
162+
"#{Util.inspect_pid(caller)} checked in the connection owned by #{Util.inspect_pid(owner)}"
162163

163164
message =
164165
case pruned_stacktrace(caller) do
@@ -167,7 +168,7 @@ defmodule DBConnection.Ownership.Proxy do
167168

168169
current_stack ->
169170
message <>
170-
"\n\n#{inspect(caller)} triggered the checkin at location:\n\n" <>
171+
"\n\n#{Util.inspect_pid(caller)} triggered the checkin at location:\n\n" <>
171172
Exception.format_stacktrace(current_stack)
172173
end
173174

@@ -237,10 +238,10 @@ defmodule DBConnection.Ownership.Proxy do
237238
current_stack ->
238239
reason <>
239240
"""
240-
\n\nClient #{inspect(client)} is still using a connection from owner at location:
241+
\n\nClient #{Util.inspect_pid(client)} is still using a connection from owner at location:
241242
242243
#{Exception.format_stacktrace(current_stack)}
243-
The connection itself was checked out by #{inspect(client)} at location:
244+
The connection itself was checked out by #{Util.inspect_pid(client)} at location:
244245
245246
#{Exception.format_stacktrace(checkout_stack)}
246247
"""

lib/db_connection/util.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule DBConnection.Util do
44
@doc """
55
Inspect a pid, including the process label if possible.
66
"""
7-
def inspect_pid(pid) do
7+
def inspect_pid(pid) when is_pid(pid) do
88
with :undefined <- get_label(pid),
99
:undefined <- get_name(pid) do
1010
inspect(pid)
@@ -13,6 +13,8 @@ defmodule DBConnection.Util do
1313
end
1414
end
1515

16+
def inspect_pid(other), do: inspect(other)
17+
1618
defp get_name(pid) do
1719
try do
1820
Process.info(pid, :registered_name)

0 commit comments

Comments
 (0)