Skip to content

Commit bbc8b7c

Browse files
committed
Changes done in except block to catch errors.
1 parent 35fbe3f commit bbc8b7c

1 file changed

Lines changed: 53 additions & 4 deletions

File tree

bugsnag/legacy.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Dict, Any, Tuple, Type, Optional, Union, List, Callable
22
import types
33
import sys
4+
import warnings
45

56
from bugsnag.breadcrumbs import BreadcrumbType, OnBreadcrumbCallback
67
from bugsnag.feature_flags import FeatureFlag
@@ -13,16 +14,64 @@
1314
ExcInfoType = Tuple[Type, Exception, types.TracebackType]
1415

1516

16-
__all__ = ('configure', 'configure_request', 'add_metadata_tab',
17-
'clear_request_config', 'notify', 'start_session', 'auto_notify',
18-
'auto_notify_exc_info', 'before_notify', 'leave_breadcrumb')
17+
__all__ = (
18+
'configure',
19+
'configure_request',
20+
'add_metadata_tab',
21+
'clear_request_config',
22+
'notify',
23+
'start_session',
24+
'auto_notify',
25+
'auto_notify_exc_info',
26+
'before_notify',
27+
'leave_breadcrumb',
28+
)
1929

2030

2131
def configure(**options):
2232
"""
2333
Configure the Bugsnag notifier application-wide settings.
2434
"""
25-
return configuration.configure(**options)
35+
# Synchronize legacy references to point at the live configuration
36+
# only `logger` is rebound in this scope
37+
global logger
38+
39+
# Delegate to the module-local configuration instance so we update the
40+
# single source of truth without resolving package submodules that may
41+
# shadow the attribute name.
42+
result = configuration.configure(**options)
43+
try:
44+
default_client.configuration = configuration
45+
except (AttributeError, TypeError, ImportError) as exc:
46+
try:
47+
configuration.logger.debug(
48+
"legacy configuration sync failed: %s", exc
49+
)
50+
except Exception:
51+
warnings.warn(
52+
f"legacy configuration sync failed: {exc}", stacklevel=2
53+
)
54+
55+
logger = configuration.logger
56+
57+
# Also update the `bugsnag` package attributes so other modules that
58+
# reference `bugsnag.configuration` / `bugsnag.logger` reflect the
59+
# live configuration object (keeps package-level attributes in sync).
60+
try:
61+
import bugsnag as _pkg
62+
setattr(_pkg, 'configuration', configuration)
63+
setattr(_pkg, 'logger', configuration.logger)
64+
except (ImportError, AttributeError, TypeError) as exc:
65+
try:
66+
configuration.logger.debug(
67+
"legacy package attr sync failed: %s", exc
68+
)
69+
except Exception:
70+
warnings.warn(
71+
f"legacy package attr sync failed: {exc}", stacklevel=2
72+
)
73+
74+
return result
2675

2776

2877
def configure_request(**options):

0 commit comments

Comments
 (0)