From 21486d7a1ec4da3b60b194a69f2abc99639ed7d1 Mon Sep 17 00:00:00 2001 From: Taranjeet Date: Sat, 5 Mar 2022 14:56:13 +0530 Subject: [PATCH] ref: Update error verbose for sentry init Provide explicit error message when calling sentry init with multiple positional arugments. --- sentry_sdk/client.py | 4 +++- tests/test_client.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 1720993c1a..1b1df35bad 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -48,6 +48,9 @@ def _get_options(*args, **kwargs): else: dsn = None + if len(args) > 1: + raise TypeError("Only single positional argument is expected") + rv = dict(DEFAULT_OPTIONS) options = dict(*args, **kwargs) if dsn is not None and options.get("dsn") is None: @@ -451,7 +454,6 @@ class get_options(ClientConstructor, Dict[str, Any]): # noqa: N801 class Client(ClientConstructor, _Client): pass - else: # Alias `get_options` for actual usage. Go through the lambda indirection # to throw PyCharm off of the weakly typed signature (it would otherwise diff --git a/tests/test_client.py b/tests/test_client.py index 9137f4115a..a9d76a4963 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -496,7 +496,7 @@ def test_scope_initialized_before_client(sentry_init, capture_events): def test_weird_chars(sentry_init, capture_events): sentry_init() events = capture_events() - capture_message(u"föö".encode("latin1")) + capture_message("föö".encode("latin1")) (event,) = events assert json.loads(json.dumps(event)) == event @@ -812,7 +812,7 @@ def __repr__(self): "dsn", [ "http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2", - u"http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2", + "http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2", ], ) def test_init_string_types(dsn, sentry_init): @@ -885,3 +885,9 @@ def test_max_breadcrumbs_option( capture_message("dogs are great") assert len(events[0]["breadcrumbs"]["values"]) == expected_breadcrumbs + + +def test_multiple_positional_args(sentry_init): + with pytest.raises(TypeError) as exinfo: + sentry_init(1, None) + assert "Only single positional argument is expected" in str(exinfo.value)