From fedf1fda81da5a7a77c3ddee21600115420696b7 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Tue, 30 Mar 2021 13:00:35 +0000 Subject: [PATCH 1/7] Inspect source of exception and filter out of module scope Reporter.name should be equal to package name. --- python/humbug/report.py | 9 ++++++++- python/setup.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/python/humbug/report.py b/python/humbug/report.py index 994117b..cf20643 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -6,6 +6,7 @@ import concurrent.futures from dataclasses import dataclass, field from enum import Enum +import inspect import os import pkg_resources import sys @@ -321,9 +322,15 @@ def setup_excepthook(self, tags: Optional[List[str]] = None, publish: bool = Tru original_excepthook = sys.excepthook def _hook(exception_type, exception_instance, traceback): - self.error_report(error=exception_instance, tags=tags, publish=publish) original_excepthook(exception_type, exception_instance, traceback) + module = inspect.getmodule(exception_type) + if module is not None: + if not module.__name__.startswith(self.name): + return + + self.error_report(error=exception_instance, tags=tags, publish=publish) + sys.excepthook = _hook self.is_excepthook_set = True diff --git a/python/setup.py b/python/setup.py index ab49495..1f3b820 100644 --- a/python/setup.py +++ b/python/setup.py @@ -6,7 +6,7 @@ setup( name="humbug", - version="0.1.14", + version="0.1.15", packages=find_packages(), install_requires=["bugout"], extras_require={ From 94f838798784ae0c7f2be2718af2e43ac794687c Mon Sep 17 00:00:00 2001 From: kompotkot Date: Wed, 31 Mar 2021 13:31:01 +0000 Subject: [PATCH 2/7] Added argument for modules_whitelist at setup_excepthook --- python/humbug/report.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/python/humbug/report.py b/python/humbug/report.py index cf20643..f3c6391 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -310,7 +310,12 @@ def compound_report( self.publish(report, wait=wait) return report - def setup_excepthook(self, tags: Optional[List[str]] = None, publish: bool = True): + def setup_excepthook( + self, + tags: Optional[List[str]] = None, + publish: bool = True, + modules_whitelist: Optional[List[str]] = None, + ) -> None: """ Adds error_report with python Exceptions. Only one excepthook will be added to stack, no matter how many @@ -321,13 +326,18 @@ def setup_excepthook(self, tags: Optional[List[str]] = None, publish: bool = Tru if not self.is_excepthook_set: original_excepthook = sys.excepthook + if modules_whitelist is None: + modules_whitelist = [] + modules_whitelist.append(self.name) + def _hook(exception_type, exception_instance, traceback): original_excepthook(exception_type, exception_instance, traceback) module = inspect.getmodule(exception_type) if module is not None: - if not module.__name__.startswith(self.name): - return + for module_whitelist in modules_whitelist: + if not module.__name__.startswith(module_whitelist): + return self.error_report(error=exception_instance, tags=tags, publish=publish) From 3bcfbbbb7039a1c11d6b18a18fbcab78ef68608b Mon Sep 17 00:00:00 2001 From: kompotkot Date: Tue, 27 Apr 2021 09:50:36 +0000 Subject: [PATCH 3/7] Fix after main merge --- python/humbug/report.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/python/humbug/report.py b/python/humbug/report.py index aeaa1e2..185d739 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -321,13 +321,6 @@ def compound_report( self.publish(report, wait=wait) return report -<<<<<<< HEAD - def setup_excepthook( - self, - tags: Optional[List[str]] = None, - publish: bool = True, - modules_whitelist: Optional[List[str]] = None, -======= def logging_report( self, record: logging.LogRecord, @@ -386,8 +379,10 @@ def record_factory(*args, **kwargs): self.is_loggerhook_set = True def setup_excepthook( - self, tags: Optional[List[str]] = None, publish: bool = True ->>>>>>> upstream/main + self, + tags: Optional[List[str]] = None, + publish: bool = True, + modules_whitelist: Optional[List[str]] = None, ) -> None: """ Adds error_report with python Exceptions. From aa994bceb12e86c0010adbc994f9ea9be55ed2b8 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Tue, 27 Apr 2021 09:55:08 +0000 Subject: [PATCH 4/7] Except changed to excert Exception for publish --- python/humbug/report.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/python/humbug/report.py b/python/humbug/report.py index 185d739..b9b2bfd 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -140,7 +140,7 @@ def publish(self, report: Report, wait: bool = False) -> None: timeout=self.timeout_seconds, ) self.report_futures.append(report_future) - except: + except Exception: pass def custom_report( @@ -394,15 +394,11 @@ def setup_excepthook( if not self.is_excepthook_set: original_excepthook = sys.excepthook - if modules_whitelist is None: - modules_whitelist = [] - modules_whitelist.append(self.name) - def _hook(exception_type, exception_instance, traceback): original_excepthook(exception_type, exception_instance, traceback) module = inspect.getmodule(exception_type) - if module is not None: + if module is not None and modules_whitelist is not None: for module_whitelist in modules_whitelist: if not module.__name__.startswith(module_whitelist): return From b7471d712566cdb2de5e53748514862dafe7c754 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Tue, 27 Apr 2021 09:58:43 +0000 Subject: [PATCH 5/7] Except Exception for old Reporter too --- python/humbug/report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/humbug/report.py b/python/humbug/report.py index b9b2bfd..b600b27 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -494,5 +494,5 @@ def publish(self, report: Report, wait: bool = False) -> None: timeout=self.timeout_seconds, ) self.report_futures.append(report_future) - except: + except Exception: pass From 99658968f18cb7892a50daab372a22501e0ac3d3 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Tue, 27 Apr 2021 13:40:02 +0000 Subject: [PATCH 6/7] Fixes for modules whitelist --- python/humbug/report.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/humbug/report.py b/python/humbug/report.py index b600b27..30b0d26 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -399,11 +399,14 @@ def _hook(exception_type, exception_instance, traceback): module = inspect.getmodule(exception_type) if module is not None and modules_whitelist is not None: + report_error = False for module_whitelist in modules_whitelist: - if not module.__name__.startswith(module_whitelist): - return - - self.error_report(error=exception_instance, tags=tags, publish=publish) + if module.__name__.startswith(module_whitelist): + report_error = True + if report_error: + self.error_report( + error=exception_instance, tags=tags, publish=publish + ) sys.excepthook = _hook From 80141515e7f0c5be5a022c42e17465a9e509ef9c Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Tue, 27 Apr 2021 10:42:27 -0700 Subject: [PATCH 7/7] small changes to excepthook with module whitelist --- python/humbug/report.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/humbug/report.py b/python/humbug/report.py index 30b0d26..06e57c9 100644 --- a/python/humbug/report.py +++ b/python/humbug/report.py @@ -398,11 +398,14 @@ def _hook(exception_type, exception_instance, traceback): original_excepthook(exception_type, exception_instance, traceback) module = inspect.getmodule(exception_type) - if module is not None and modules_whitelist is not None: - report_error = False - for module_whitelist in modules_whitelist: - if module.__name__.startswith(module_whitelist): + report_error = False + if modules_whitelist is None: + report_error = True + elif module is not None and modules_whitelist is not None: + for whitelisted_module in modules_whitelist: + if module.__name__.startswith(whitelisted_module): report_error = True + if report_error: self.error_report( error=exception_instance, tags=tags, publish=publish