Skip to content

Commit 726b347

Browse files
committed
Removes unreachable case in retrieving remote port value
The _ case would never match, as the previous clause would cover all cases being returned from Plug.Conn.get_peer_data(conn). The dialyzer warning: ``` lib/sentry/plug.ex:187: The variable _ can never match since previous clauses completely covered the type #{'address':={byte(),byte(),byte(),byte()} | {char(),char(),char(),char(),char(),char(),char(),char()}, 'port':=char(), 'ssl_cert':='nil' | binary()} ``` When removing that default case, the need for the case statement disappeared, and we can just fetch the remote port inline on LN174 instead.
1 parent faac6c3 commit 726b347

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

lib/sentry/plug.ex

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,14 @@ if Code.ensure_loaded?(Plug) do
171171
headers: handle_data(conn, header_scrubber),
172172
env: %{
173173
"REMOTE_ADDR" => remote_address(conn.remote_ip),
174-
"REMOTE_PORT" => remote_port(conn),
174+
"REMOTE_PORT" => Plug.Conn.get_peer_data(conn).port,
175175
"SERVER_NAME" => conn.host,
176176
"SERVER_PORT" => conn.port,
177177
"REQUEST_ID" => Plug.Conn.get_resp_header(conn, request_id) |> List.first()
178178
}
179179
}
180180
end
181181

182-
defp remote_port(conn) do
183-
case Plug.Conn.get_peer_data(conn) do
184-
%{port: port} ->
185-
port
186-
187-
_ ->
188-
""
189-
end
190-
end
191-
192182
defp remote_address(address) do
193183
address
194184
|> :inet.ntoa()

0 commit comments

Comments
 (0)