Skip to content

Commit d941a29

Browse files
Merge pull request #348 from mathiasose/dsn-nil-error
Check that DSN is binary before trying URI.parse
2 parents a9e6209 + b1e5623 commit d941a29

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/sentry/client.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ defmodule Sentry.Client do
222222
def get_dsn do
223223
dsn = Config.dsn()
224224

225-
with %URI{userinfo: userinfo, host: host, port: port, path: path, scheme: protocol}
225+
with dsn when is_binary(dsn) <- dsn,
226+
%URI{userinfo: userinfo, host: host, port: port, path: path, scheme: protocol}
226227
when is_binary(path) and is_binary(userinfo) <- URI.parse(dsn),
227228
[public_key, secret_key] <- keys_from_userinfo(userinfo),
228229
[_, binary_project_id] <- String.split(path, "/"),

test/client_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ defmodule Sentry.ClientTest do
6565
end)
6666
end
6767

68+
test "errors on nil dsn" do
69+
modify_env(:sentry, dsn: nil)
70+
71+
capture_log(fn ->
72+
assert :error = Sentry.Client.get_dsn()
73+
end)
74+
end
75+
76+
test "errors on atom dsn" do
77+
modify_env(:sentry, dsn: :error)
78+
79+
capture_log(fn ->
80+
assert :error = Sentry.Client.get_dsn()
81+
end)
82+
end
83+
6884
test "logs api errors" do
6985
bypass = Bypass.open()
7086

0 commit comments

Comments
 (0)