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

Handle a number of bad failure-path behaviors (#1807) #1839

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 3 deletions core/dbt/adapters/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ def get_thread_connection(self) -> Connection:
key = self.get_thread_identifier()
with self.lock:
if key not in self.thread_connections:
raise RuntimeError(
'connection never acquired for thread {}, have {}'
.format(key, list(self.thread_connections))
raise dbt.exceptions.InvalidConnectionException(
key, list(self.thread_connections)
)
return self.thread_connections[key]

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def commit_if_has_connection(self):
return self.connections.commit_if_has_connection()

def nice_connection_name(self):
conn = self.connections.get_thread_connection()
conn = self.connections.get_if_exists()
if conn is None or conn.name is None:
return '<None>'
return conn.name
Expand Down
10 changes: 10 additions & 0 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ def __str__(self):
return '{} running: {}'.format(self.msg, self.cmd)


class InvalidConnectionException(RuntimeException):
def __init__(self, thread_id, known, node=None):
self.thread_id = thread_id
self.known = known
super().__init__(
msg='connection never acquired for thread {}, have {}'
.format(self.thread_id, self.known)
)


def raise_compiler_error(msg, node=None) -> NoReturn:
raise CompilationException(msg, node)

Expand Down
4 changes: 2 additions & 2 deletions plugins/bigquery/dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def handle_error(cls, error, message, sql):
error_msg = "\n".join(
[item['message'] for item in error.errors])

raise dbt.exceptions.DatabaseException(error_msg)
raise dbt.exceptions.DatabaseException(error_msg) from error

def clear_transaction(self):
pass
Expand All @@ -90,7 +90,7 @@ def exception_handler(self, sql):
# this sounds a lot like a signal handler and probably has
# useful information, so raise it without modification.
raise
raise dbt.exceptions.RuntimeException(str(e))
raise dbt.exceptions.RuntimeException(str(e)) from e

def cancel_open(self) -> None:
pass
Expand Down
4 changes: 2 additions & 2 deletions plugins/postgres/dbt/adapters/postgres/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def exception_handler(self, sql):
logger.debug("Failed to release connection!")
pass

raise dbt.exceptions.DatabaseException(str(e).strip())
raise dbt.exceptions.DatabaseException(str(e).strip()) from e

except Exception as e:
logger.debug("Error running SQL: {}", sql)
Expand All @@ -64,7 +64,7 @@ def exception_handler(self, sql):
# useful information, so raise it without modification.
raise

raise dbt.exceptions.RuntimeException(e)
raise dbt.exceptions.RuntimeException(e) from e

@classmethod
def open(cls, connection):
Expand Down
2 changes: 1 addition & 1 deletion plugins/snowflake/dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def exception_handler(self, sql):
# this sounds a lot like a signal handler and probably has
# useful information, so raise it without modification.
raise
raise dbt.exceptions.RuntimeException(e.msg)
raise dbt.exceptions.RuntimeException(str(e)) from e

@classmethod
def open(cls, connection):
Expand Down