From ee5e78d6f3d006e924b5950546d99c340ddaaa4c Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 21 Dec 2021 13:09:17 -0500 Subject: [PATCH 1/4] Fix handling of top-level exceptions --- core/dbt/events/base_types.py | 2 ++ core/dbt/events/test_types.py | 3 ++- core/dbt/events/types.py | 19 +++++++++---------- core/dbt/main.py | 1 - 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/dbt/events/base_types.py b/core/dbt/events/base_types.py index bc48c06396a..6e9af2f5059 100644 --- a/core/dbt/events/base_types.py +++ b/core/dbt/events/base_types.py @@ -105,6 +105,8 @@ def level_tag(self) -> str: # prevents an event from going to the file +# This should not be used in core code. It is currently +# only used in integration tests. class NoFile: pass diff --git a/core/dbt/events/test_types.py b/core/dbt/events/test_types.py index f9573ed399f..291c9493a51 100644 --- a/core/dbt/events/test_types.py +++ b/core/dbt/events/test_types.py @@ -1,5 +1,6 @@ from dataclasses import dataclass -from .types import InfoLevel, DebugLevel, WarnLevel, ErrorLevel, ShowException, NoFile +from dbt.events.types import InfoLevel, DebugLevel, WarnLevel, ErrorLevel, ShowException +from dbt.events.base_types import NoFile # Keeping log messages for testing separate since they are used for debugging. diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index 25bdea84f78..22faec19f93 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -4,7 +4,6 @@ from dbt.helper_types import Lazy from dbt.events.base_types import ( Event, - NoFile, DebugLevel, InfoLevel, WarnLevel, @@ -94,7 +93,7 @@ class AdapterEventError(ErrorLevel, AdapterEventBase, ShowException): @dataclass -class MainKeyboardInterrupt(InfoLevel, NoFile): +class MainKeyboardInterrupt(InfoLevel): code: str = "Z001" def message(self) -> str: @@ -102,7 +101,7 @@ def message(self) -> str: @dataclass -class MainEncounteredError(ErrorLevel, NoFile): +class MainEncounteredError(ErrorLevel): e: BaseException code: str = "Z002" @@ -111,7 +110,7 @@ def message(self) -> str: @dataclass -class MainStackTrace(DebugLevel, NoFile): +class MainStackTrace(ErrorLevel): stack_trace: str code: str = "Z003" @@ -1354,7 +1353,7 @@ def message(self) -> str: @dataclass -class CheckCleanPath(InfoLevel, NoFile): +class CheckCleanPath(InfoLevel): path: str code: str = "Z012" @@ -1363,7 +1362,7 @@ def message(self) -> str: @dataclass -class ConfirmCleanPath(InfoLevel, NoFile): +class ConfirmCleanPath(InfoLevel): path: str code: str = "Z013" @@ -1372,7 +1371,7 @@ def message(self) -> str: @dataclass -class ProtectedCleanPath(InfoLevel, NoFile): +class ProtectedCleanPath(InfoLevel): path: str code: str = "Z014" @@ -1381,7 +1380,7 @@ def message(self) -> str: @dataclass -class FinishedCleanPaths(InfoLevel, NoFile): +class FinishedCleanPaths(InfoLevel): code: str = "Z015" def message(self) -> str: @@ -2382,7 +2381,7 @@ def message(self) -> str: @dataclass -class FlushEvents(DebugLevel, NoFile): +class FlushEvents(DebugLevel): code: str = "Z042" def message(self) -> str: @@ -2390,7 +2389,7 @@ def message(self) -> str: @dataclass -class FlushEventsFailure(DebugLevel, NoFile): +class FlushEventsFailure(DebugLevel): code: str = "Z043" def message(self) -> str: diff --git a/core/dbt/main.py b/core/dbt/main.py index c187591185e..561c8c1353a 100644 --- a/core/dbt/main.py +++ b/core/dbt/main.py @@ -142,7 +142,6 @@ def main(args=None): exit_code = e.code except BaseException as e: - traceback.print_exc() fire_event(MainEncounteredError(e=str(e))) fire_event(MainStackTrace(stack_trace=traceback.format_exc())) exit_code = ExitCodes.UnhandledError.value From 2f3fd22b3b091ca236bf7fe461160d6023be52d5 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 26 Jul 2022 11:36:44 -0400 Subject: [PATCH 2/4] Changie --- .changes/unreleased/Fixes-20220726-113636.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changes/unreleased/Fixes-20220726-113636.yaml diff --git a/.changes/unreleased/Fixes-20220726-113636.yaml b/.changes/unreleased/Fixes-20220726-113636.yaml new file mode 100644 index 00000000000..220507749cf --- /dev/null +++ b/.changes/unreleased/Fixes-20220726-113636.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Fix handling of top-level exceptions +time: 2022-07-26T11:36:36.824979-04:00 +custom: + Author: gshank + Issue: "4357" + PR: "5560" From cc8592f4d9043d40d02321a23ab3e7781b206de3 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 26 Jul 2022 13:46:56 -0400 Subject: [PATCH 3/4] Put NoFile back on clean events --- core/dbt/events/base_types.py | 4 ++-- core/dbt/events/functions.py | 2 +- core/dbt/events/types.py | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/dbt/events/base_types.py b/core/dbt/events/base_types.py index 6e9af2f5059..ce33b4955c4 100644 --- a/core/dbt/events/base_types.py +++ b/core/dbt/events/base_types.py @@ -105,8 +105,8 @@ def level_tag(self) -> str: # prevents an event from going to the file -# This should not be used in core code. It is currently -# only used in integration tests. +# This should rarely be used in core code. It is currently +# only used in integration tests and for the 'clean' command. class NoFile: pass diff --git a/core/dbt/events/functions.py b/core/dbt/events/functions.py index a77ab6d4079..62d86ecf0ce 100644 --- a/core/dbt/events/functions.py +++ b/core/dbt/events/functions.py @@ -218,7 +218,7 @@ def create_log_line(e: T_Event, file_output=False) -> Optional[str]: return create_info_text_log_line(e) # console output -# allows for resuse of this obnoxious if else tree. +# allows for reuse of this obnoxious if else tree. # do not use for exceptions, it doesn't pass along exc_info, stack_info, or extra def send_to_logger(l: Union[Logger, logbook.Logger], level_tag: str, log_line: str): if not log_line: diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index 22faec19f93..06faf151eee 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -4,6 +4,7 @@ from dbt.helper_types import Lazy from dbt.events.base_types import ( Event, + NoFile, DebugLevel, InfoLevel, WarnLevel, @@ -1352,8 +1353,10 @@ def message(self) -> str: return "Error releasing connection for node {}: {!s}".format(self.node_name, self.exc) +# We don't write "clean" events to the log, because the clean command +# may have removed the log directory. @dataclass -class CheckCleanPath(InfoLevel): +class CheckCleanPath(InfoLevel, NoFile): path: str code: str = "Z012" @@ -1362,7 +1365,7 @@ def message(self) -> str: @dataclass -class ConfirmCleanPath(InfoLevel): +class ConfirmCleanPath(InfoLevel, NoFile): path: str code: str = "Z013" @@ -1371,7 +1374,7 @@ def message(self) -> str: @dataclass -class ProtectedCleanPath(InfoLevel): +class ProtectedCleanPath(InfoLevel, NoFile): path: str code: str = "Z014" @@ -1380,7 +1383,7 @@ def message(self) -> str: @dataclass -class FinishedCleanPaths(InfoLevel): +class FinishedCleanPaths(InfoLevel, NoFile): code: str = "Z015" def message(self) -> str: From 1c61be1a8179e2ac1faa7ea3200df656863a12b5 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Wed, 27 Jul 2022 09:38:10 -0400 Subject: [PATCH 4/4] Update changie --- .changes/unreleased/Fixes-20220726-113636.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/unreleased/Fixes-20220726-113636.yaml b/.changes/unreleased/Fixes-20220726-113636.yaml index 220507749cf..abd9da36d01 100644 --- a/.changes/unreleased/Fixes-20220726-113636.yaml +++ b/.changes/unreleased/Fixes-20220726-113636.yaml @@ -3,5 +3,5 @@ body: Fix handling of top-level exceptions time: 2022-07-26T11:36:36.824979-04:00 custom: Author: gshank - Issue: "4357" + Issue: "5564" PR: "5560"