diff --git a/lib/sentry/client.ex b/lib/sentry/client.ex index c8fb0974..110bc1cc 100644 --- a/lib/sentry/client.ex +++ b/lib/sentry/client.ex @@ -222,7 +222,8 @@ defmodule Sentry.Client do def get_dsn do dsn = Config.dsn() - with %URI{userinfo: userinfo, host: host, port: port, path: path, scheme: protocol} + with dsn when is_binary(dsn) <- dsn, + %URI{userinfo: userinfo, host: host, port: port, path: path, scheme: protocol} when is_binary(path) and is_binary(userinfo) <- URI.parse(dsn), [public_key, secret_key] <- keys_from_userinfo(userinfo), [_, binary_project_id] <- String.split(path, "/"), diff --git a/test/client_test.exs b/test/client_test.exs index 42da1ffe..e66ffa59 100644 --- a/test/client_test.exs +++ b/test/client_test.exs @@ -65,6 +65,22 @@ defmodule Sentry.ClientTest do end) end + test "errors on nil dsn" do + modify_env(:sentry, dsn: nil) + + capture_log(fn -> + assert :error = Sentry.Client.get_dsn() + end) + end + + test "errors on atom dsn" do + modify_env(:sentry, dsn: :error) + + capture_log(fn -> + assert :error = Sentry.Client.get_dsn() + end) + end + test "logs api errors" do bypass = Bypass.open()