Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename exceptions #6539

Merged
merged 34 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9e88743
rename InternalException
emmyoop Dec 20, 2022
9e4a844
rename RuntimeException
emmyoop Dec 20, 2022
e4cc396
rename DatabaseException
emmyoop Dec 20, 2022
472db28
rename CompilationException
emmyoop Dec 20, 2022
386e39d
cleanup renames in tests and postgres
emmyoop Dec 20, 2022
2c7f2df
rename ValidationException
emmyoop Dec 20, 2022
aa626d9
rename IncompatibleSchemaException
emmyoop Dec 20, 2022
ab864ae
more renaming
emmyoop Dec 20, 2022
f75726c
more renaming
emmyoop Dec 20, 2022
60f29d8
rename InternalException again
emmyoop Dec 20, 2022
96a3688
convert ParsingException
emmyoop Jan 6, 2023
5b4097d
replace JSONValidationException and SemverException
emmyoop Jan 6, 2023
8012a7b
replace VersionsNotCompatibleException
emmyoop Jan 6, 2023
a5bf8a0
replace NotImplementedException
emmyoop Jan 6, 2023
25eb5d2
replace FailedToConnectException
emmyoop Jan 6, 2023
875a91c
replace InvalidConnectionException
emmyoop Jan 6, 2023
3509d93
replace InvalidSelectorException
emmyoop Jan 6, 2023
360f728
replace DuplicateYamlKeyException
emmyoop Jan 6, 2023
06ab3ab
replace ConnectionException
emmyoop Jan 6, 2023
8c8ff9b
minor cleanup
emmyoop Jan 6, 2023
1917178
update comment
emmyoop Jan 9, 2023
11ef94f
more cleanup
emmyoop Jan 9, 2023
60d586f
add class decorator
emmyoop Jan 10, 2023
5f65a19
rename more exceptions
emmyoop Jan 10, 2023
f80376e
more renamed, add changelog
emmyoop Jan 10, 2023
f8e6b32
rename exception
emmyoop Jan 10, 2023
a7f9bc2
rework class deprecations
emmyoop Jan 10, 2023
bf7ce71
removing testing line
emmyoop Jan 10, 2023
48e04e2
fix failing test
emmyoop Jan 10, 2023
1729ff5
rename newer exceptions
emmyoop Jan 10, 2023
2df619d
fix failing test
emmyoop Jan 10, 2023
e41580f
commit unsaved faile
emmyoop Jan 10, 2023
ee154f0
convert back an rpc exception
emmyoop Jan 10, 2023
6e8f95f
remove class deprecations
emmyoop Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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