Skip to content

Commit

Permalink
Fix handling of top-level exceptions (#5560) (#5570)
Browse files Browse the repository at this point in the history
(cherry picked from commit b43fc76)

Co-authored-by: Gerda Shank <gerda@dbtlabs.com>
  • Loading branch information
github-actions[bot] and gshank authored Jul 28, 2022
1 parent c7652f6 commit 9c32441
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20220726-113636.yaml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions core/dbt/events/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/events/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/events/test_types.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 7 additions & 5 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ class AdapterEventError(ErrorLevel, AdapterEventBase, ShowException):


@dataclass
class MainKeyboardInterrupt(InfoLevel, NoFile):
class MainKeyboardInterrupt(InfoLevel):
code: str = "Z001"

def message(self) -> str:
return "ctrl-c"


@dataclass
class MainEncounteredError(ErrorLevel, NoFile):
class MainEncounteredError(ErrorLevel):
e: BaseException
code: str = "Z002"

Expand All @@ -111,7 +111,7 @@ def message(self) -> str:


@dataclass
class MainStackTrace(DebugLevel, NoFile):
class MainStackTrace(ErrorLevel):
stack_trace: str
code: str = "Z003"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2382,15 +2384,15 @@ def message(self) -> str:


@dataclass
class FlushEvents(DebugLevel, NoFile):
class FlushEvents(DebugLevel):
code: str = "Z042"

def message(self) -> str:
return "Flushing usage events"


@dataclass
class FlushEventsFailure(DebugLevel, NoFile):
class FlushEventsFailure(DebugLevel):
code: str = "Z043"

def message(self) -> str:
Expand Down
1 change: 0 additions & 1 deletion core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c32441

Please sign in to comment.