diff --git a/.changes/unreleased/Fixes-20220726-113636.yaml b/.changes/unreleased/Fixes-20220726-113636.yaml new file mode 100644 index 00000000000..abd9da36d01 --- /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: "5564" + PR: "5560" diff --git a/core/dbt/events/base_types.py b/core/dbt/events/base_types.py index bc48c06396a..ce33b4955c4 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 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/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..06faf151eee 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -94,7 +94,7 @@ class AdapterEventError(ErrorLevel, AdapterEventBase, ShowException): @dataclass -class MainKeyboardInterrupt(InfoLevel, NoFile): +class MainKeyboardInterrupt(InfoLevel): code: str = "Z001" def message(self) -> str: @@ -102,7 +102,7 @@ def message(self) -> str: @dataclass -class MainEncounteredError(ErrorLevel, NoFile): +class MainEncounteredError(ErrorLevel): e: BaseException code: str = "Z002" @@ -111,7 +111,7 @@ def message(self) -> str: @dataclass -class MainStackTrace(DebugLevel, NoFile): +class MainStackTrace(ErrorLevel): stack_trace: str code: str = "Z003" @@ -1353,6 +1353,8 @@ 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, NoFile): path: str @@ -2382,7 +2384,7 @@ def message(self) -> str: @dataclass -class FlushEvents(DebugLevel, NoFile): +class FlushEvents(DebugLevel): code: str = "Z042" def message(self) -> str: @@ -2390,7 +2392,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