Skip to content

Commit

Permalink
Rename exceptions (#6539)
Browse files Browse the repository at this point in the history
* rename InternalException

* rename RuntimeException

* rename DatabaseException

* rename CompilationException

* cleanup renames in tests and postgres

* rename ValidationException

* rename IncompatibleSchemaException

* more renaming

* more renaming

* rename InternalException again

* convert ParsingException

* replace JSONValidationException and SemverException

* replace VersionsNotCompatibleException

* replace NotImplementedException

* replace FailedToConnectException

* replace InvalidConnectionException

* replace InvalidSelectorException

* replace DuplicateYamlKeyException

* replace ConnectionException

* minor cleanup

* update comment

* more cleanup

* add class decorator

* rename more exceptions

* more renamed, add changelog

* rename exception

* rework class deprecations

* removing testing line

* fix failing test

* rename newer exceptions

* fix failing test

* commit unsaved faile

* convert back an rpc exception

* remove class deprecations
  • Loading branch information
emmyoop authored Jan 10, 2023
1 parent 0fc080d commit eb200b4
Show file tree
Hide file tree
Showing 148 changed files with 1,330 additions and 1,332 deletions.
5 changes: 3 additions & 2 deletions .changes/unreleased/Breaking Changes-20221205-141937.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
kind: Breaking Changes
body: Cleaned up exceptions to directly raise in code. Removed use of all exception
body: Cleaned up exceptions to directly raise in code. Also updated the existing
exception to meet PEP guidelines.Removed use of all exception
functions in the code base and marked them all as deprecated to be removed next
minor release.
time: 2022-12-05T14:19:37.863032-06:00
custom:
Author: emmyoop
Issue: 6339 6393
Issue: 6339 6393 6460
12 changes: 6 additions & 6 deletions core/dbt/adapters/base/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from typing import Dict, ClassVar, Any, Optional

from dbt.exceptions import RuntimeException
from dbt.exceptions import DbtRuntimeError


@dataclass
Expand Down Expand Up @@ -85,7 +85,7 @@ def is_numeric(self) -> bool:

def string_size(self) -> int:
if not self.is_string():
raise RuntimeException("Called string_size() on non-string field!")
raise DbtRuntimeError("Called string_size() on non-string field!")

if self.dtype == "text" or self.char_size is None:
# char_size should never be None. Handle it reasonably just in case
Expand Down Expand Up @@ -124,7 +124,7 @@ def __repr__(self) -> str:
def from_description(cls, name: str, raw_data_type: str) -> "Column":
match = re.match(r"([^(]+)(\([^)]+\))?", raw_data_type)
if match is None:
raise RuntimeException(f'Could not interpret data type "{raw_data_type}"')
raise DbtRuntimeError(f'Could not interpret data type "{raw_data_type}"')
data_type, size_info = match.groups()
char_size = None
numeric_precision = None
Expand All @@ -137,22 +137,22 @@ def from_description(cls, name: str, raw_data_type: str) -> "Column":
try:
char_size = int(parts[0])
except ValueError:
raise RuntimeException(
raise DbtRuntimeError(
f'Could not interpret data_type "{raw_data_type}": '
f'could not convert "{parts[0]}" to an integer'
)
elif len(parts) == 2:
try:
numeric_precision = int(parts[0])
except ValueError:
raise RuntimeException(
raise DbtRuntimeError(
f'Could not interpret data_type "{raw_data_type}": '
f'could not convert "{parts[0]}" to an integer'
)
try:
numeric_scale = int(parts[1])
except ValueError:
raise RuntimeException(
raise DbtRuntimeError(
f'Could not interpret data_type "{raw_data_type}": '
f'could not convert "{parts[1]}" to an integer'
)
Expand Down
36 changes: 15 additions & 21 deletions core/dbt/adapters/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def get_thread_connection(self) -> Connection:
key = self.get_thread_identifier()
with self.lock:
if key not in self.thread_connections:
raise dbt.exceptions.InvalidConnectionException(key, list(self.thread_connections))
raise dbt.exceptions.InvalidConnectionError(key, list(self.thread_connections))
return self.thread_connections[key]

def set_thread_connection(self, conn: Connection) -> None:
key = self.get_thread_identifier()
if key in self.thread_connections:
raise dbt.exceptions.InternalException(
raise dbt.exceptions.DbtInternalError(
"In set_thread_connection, existing connection exists for {}"
)
self.thread_connections[key] = conn
Expand Down Expand Up @@ -137,7 +137,7 @@ def exception_handler(self, sql: str) -> ContextManager:
:return: A context manager that handles exceptions raised by the
underlying database.
"""
raise dbt.exceptions.NotImplementedException(
raise dbt.exceptions.NotImplementedError(
"`exception_handler` is not implemented for this adapter!"
)

Expand Down Expand Up @@ -211,7 +211,7 @@ def retry_connection(
connect should trigger a retry.
:type retryable_exceptions: Iterable[Type[Exception]]
:param int retry_limit: How many times to retry the call to connect. If this limit
is exceeded before a successful call, a FailedToConnectException will be raised.
is exceeded before a successful call, a FailedToConnectError will be raised.
Must be non-negative.
:param retry_timeout: Time to wait between attempts to connect. Can also take a
Callable that takes the number of attempts so far, beginning at 0, and returns an int
Expand All @@ -220,22 +220,22 @@ def retry_connection(
:param int _attempts: Parameter used to keep track of the number of attempts in calling the
connect function across recursive calls. Passed as an argument to retry_timeout if it
is a Callable. This parameter should not be set by the initial caller.
:raises dbt.exceptions.FailedToConnectException: Upon exhausting all retry attempts without
:raises dbt.exceptions.FailedToConnectError: Upon exhausting all retry attempts without
successfully acquiring a handle.
:return: The given connection with its appropriate state and handle attributes set
depending on whether we successfully acquired a handle or not.
"""
timeout = retry_timeout(_attempts) if callable(retry_timeout) else retry_timeout
if timeout < 0:
raise dbt.exceptions.FailedToConnectException(
raise dbt.exceptions.FailedToConnectError(
"retry_timeout cannot be negative or return a negative time."
)

if retry_limit < 0 or retry_limit > sys.getrecursionlimit():
# This guard is not perfect others may add to the recursion limit (e.g. built-ins).
connection.handle = None
connection.state = ConnectionState.FAIL
raise dbt.exceptions.FailedToConnectException("retry_limit cannot be negative")
raise dbt.exceptions.FailedToConnectError("retry_limit cannot be negative")

try:
connection.handle = connect()
Expand All @@ -246,7 +246,7 @@ def retry_connection(
if retry_limit <= 0:
connection.handle = None
connection.state = ConnectionState.FAIL
raise dbt.exceptions.FailedToConnectException(str(e))
raise dbt.exceptions.FailedToConnectError(str(e))

logger.debug(
f"Got a retryable error when attempting to open a {cls.TYPE} connection.\n"
Expand All @@ -268,12 +268,12 @@ def retry_connection(
except Exception as e:
connection.handle = None
connection.state = ConnectionState.FAIL
raise dbt.exceptions.FailedToConnectException(str(e))
raise dbt.exceptions.FailedToConnectError(str(e))

@abc.abstractmethod
def cancel_open(self) -> Optional[List[str]]:
"""Cancel all open connections on the adapter. (passable)"""
raise dbt.exceptions.NotImplementedException(
raise dbt.exceptions.NotImplementedError(
"`cancel_open` is not implemented for this adapter!"
)

Expand All @@ -288,7 +288,7 @@ def open(cls, connection: Connection) -> Connection:
This should be thread-safe, or hold the lock if necessary. The given
connection should not be in either in_use or available.
"""
raise dbt.exceptions.NotImplementedException("`open` is not implemented for this adapter!")
raise dbt.exceptions.NotImplementedError("`open` is not implemented for this adapter!")

def release(self) -> None:
with self.lock:
Expand Down Expand Up @@ -320,16 +320,12 @@ def cleanup_all(self) -> None:
@abc.abstractmethod
def begin(self) -> None:
"""Begin a transaction. (passable)"""
raise dbt.exceptions.NotImplementedException(
"`begin` is not implemented for this adapter!"
)
raise dbt.exceptions.NotImplementedError("`begin` is not implemented for this adapter!")

@abc.abstractmethod
def commit(self) -> None:
"""Commit a transaction. (passable)"""
raise dbt.exceptions.NotImplementedException(
"`commit` is not implemented for this adapter!"
)
raise dbt.exceptions.NotImplementedError("`commit` is not implemented for this adapter!")

@classmethod
def _rollback_handle(cls, connection: Connection) -> None:
Expand Down Expand Up @@ -365,7 +361,7 @@ def _close_handle(cls, connection: Connection) -> None:
def _rollback(cls, connection: Connection) -> None:
"""Roll back the given connection."""
if connection.transaction_open is False:
raise dbt.exceptions.InternalException(
raise dbt.exceptions.DbtInternalError(
f"Tried to rollback transaction on connection "
f'"{connection.name}", but it does not have one open!'
)
Expand Down Expand Up @@ -415,6 +411,4 @@ def execute(
:return: A tuple of the query status and results (empty if fetch=False).
:rtype: Tuple[AdapterResponse, agate.Table]
"""
raise dbt.exceptions.NotImplementedException(
"`execute` is not implemented for this adapter!"
)
raise dbt.exceptions.NotImplementedError("`execute` is not implemented for this adapter!")
Loading

0 comments on commit eb200b4

Please sign in to comment.