Skip to content

Commit

Permalink
update exception names (#460)
Browse files Browse the repository at this point in the history
* update exception names

* point back to main

* Update Under the Hood-20230110-110016.yaml
  • Loading branch information
emmyoop authored Jan 11, 2023
1 parent 2e06977 commit 3ce88d7
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 47 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20230110-110016.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Update exception names to match dbt-core
time: 2023-01-10T11:00:16.649793-06:00
custom:
Author: emmyoop
Issue: "441"
PR: "460"
18 changes: 9 additions & 9 deletions dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from dbt.tracking import active_user
from dbt.contracts.connection import ConnectionState, AdapterResponse
from dbt.exceptions import (
FailedToConnectException,
RuntimeException,
DatabaseException,
FailedToConnectError,
DbtRuntimeError,
DbtDatabaseError,
DbtProfileError,
)
from dbt.adapters.base import BaseConnectionManager, Credentials
Expand Down Expand Up @@ -196,7 +196,7 @@ def handle_error(cls, error, message):
error.query_job.location, error.query_job.project, error.query_job.job_id
)
)
raise DatabaseException(error_msg)
raise DbtDatabaseError(error_msg)

def clear_transaction(self):
pass
Expand All @@ -223,12 +223,12 @@ def exception_handler(self, sql):
"account you are trying to impersonate.\n\n"
f"{str(e)}"
)
raise RuntimeException(message)
raise DbtRuntimeError(message)

except Exception as e:
logger.debug("Unhandled error while running:\n{}".format(sql))
logger.debug(e)
if isinstance(e, RuntimeException):
if isinstance(e, DbtRuntimeError):
# during a sql query, an internal to dbt exception was raised.
# this sounds a lot like a signal handler and probably has
# useful information, so raise it without modification.
Expand All @@ -238,7 +238,7 @@ def exception_handler(self, sql):
# don't want to log. Hopefully they never change this!
if BQ_QUERY_JOB_SPLIT in exc_message:
exc_message = exc_message.split(BQ_QUERY_JOB_SPLIT)[0].strip()
raise RuntimeException(exc_message)
raise DbtRuntimeError(exc_message)

def cancel_open(self) -> None:
pass
Expand Down Expand Up @@ -305,7 +305,7 @@ def get_google_credentials(cls, profile_credentials) -> GoogleCredentials:
)

error = 'Invalid `method` in profile: "{}"'.format(method)
raise FailedToConnectException(error)
raise FailedToConnectError(error)

@classmethod
def get_impersonated_credentials(cls, profile_credentials):
Expand Down Expand Up @@ -362,7 +362,7 @@ def open(cls, connection):
connection.handle = None
connection.state = "fail"

raise FailedToConnectException(str(e))
raise FailedToConnectError(str(e))

connection.handle = handle
connection.state = "open"
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/bigquery/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def setup_default_credentials():
if gcloud_installed():
run_cmd(".", ["gcloud", "auth", "application-default", "login"])
else:
raise dbt.exceptions.RuntimeException(NOT_INSTALLED_MSG)
raise dbt.exceptions.DbtRuntimeError(NOT_INSTALLED_MSG)
22 changes: 10 additions & 12 deletions dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

def sql_escape(string):
if not isinstance(string, str):
raise dbt.exceptions.CompilationException(f"cannot escape a non-string: {string}")
raise dbt.exceptions.CompilationError(f"cannot escape a non-string: {string}")
return json.dumps(string)[1:-1]


Expand Down Expand Up @@ -98,9 +98,9 @@ def parse(cls, raw_partition_by) -> Optional["PartitionConfig"]:
cls.validate(raw_partition_by)
return cls.from_dict(raw_partition_by)
except ValidationError as exc:
raise dbt.exceptions.ValidationException("Could not parse partition config") from exc
raise dbt.exceptions.DbtValidationError("Could not parse partition config") from exc
except TypeError:
raise dbt.exceptions.CompilationException(
raise dbt.exceptions.CompilationError(
f"Invalid partition_by config:\n"
f" Got: {raw_partition_by}\n"
f' Expected a dictionary with "field" and "data_type" keys'
Expand Down Expand Up @@ -173,9 +173,7 @@ def drop_relation(self, relation: BigQueryRelation) -> None:
conn.handle.delete_table(table_ref)

def truncate_relation(self, relation: BigQueryRelation) -> None:
raise dbt.exceptions.NotImplementedException(
"`truncate` is not implemented for this adapter!"
)
raise dbt.exceptions.NotImplementedError("`truncate` is not implemented for this adapter!")

def rename_relation(
self, from_relation: BigQueryRelation, to_relation: BigQueryRelation
Expand All @@ -191,7 +189,7 @@ def rename_relation(
or from_relation.type == RelationType.View
or to_relation.type == RelationType.View
):
raise dbt.exceptions.RuntimeException(
raise dbt.exceptions.DbtRuntimeError(
"Renaming of views is not currently supported in BigQuery"
)

Expand Down Expand Up @@ -440,7 +438,7 @@ def copy_table(self, source, destination, materialization):
elif materialization == "table":
write_disposition = WRITE_TRUNCATE
else:
dbt.exceptions.raise_compiler_error(
raise dbt.exceptions.CompilationError(
'Copy table materialization must be "copy" or "table", but '
f"config.get('copy_materialization', 'table') was "
f"{materialization}"
Expand Down Expand Up @@ -473,11 +471,11 @@ def poll_until_job_completes(cls, job, timeout):
job.reload()

if job.state != "DONE":
raise dbt.exceptions.RuntimeException("BigQuery Timeout Exceeded")
raise dbt.exceptions.DbtRuntimeError("BigQuery Timeout Exceeded")

elif job.error_result:
message = "\n".join(error["message"].strip() for error in job.errors)
raise dbt.exceptions.RuntimeException(message)
raise dbt.exceptions.DbtRuntimeError(message)

def _bq_table_to_relation(self, bq_table):
if bq_table is None:
Expand All @@ -502,7 +500,7 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False):
if self.nice_connection_name() in ["on-run-start", "on-run-end"]:
self.warning_on_hooks(self.nice_connection_name())
else:
raise dbt.exceptions.NotImplementedException(
raise dbt.exceptions.NotImplementedError(
"`add_query` is not implemented for this adapter!"
)

Expand Down Expand Up @@ -860,7 +858,7 @@ def string_add_sql(
elif location == "prepend":
return f"concat('{value}', {add_to})"
else:
raise dbt.exceptions.RuntimeException(
raise dbt.exceptions.DbtRuntimeError(
f'Got an unexpected location value of "{location}"'
)

Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/bigquery/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from itertools import chain, islice

from dbt.adapters.base.relation import BaseRelation, ComponentName, InformationSchema
from dbt.exceptions import raise_compiler_error
from dbt.exceptions import CompilationError
from dbt.utils import filter_null_values
from typing import TypeVar

Expand Down Expand Up @@ -94,7 +94,7 @@ def from_relation(cls, relation, information_schema_view):
msg = (
f'No location/region found when trying to retrieve "{information_schema_view}"'
)
raise raise_compiler_error(msg)
raise CompilationError(msg)
info_schema = info_schema.incorporate(location=relation.location)
return info_schema

Expand Down
2 changes: 0 additions & 2 deletions tests/integration/schema_tests_test/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os

from dbt.task.test import TestTask
from dbt.exceptions import CompilationException
from dbt.contracts.results import TestStatus

class TestBQSchemaTests(DBTIntegrationTest):
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from tests.integration.base import DBTIntegrationTest, use_profile
from datetime import datetime
import pytz
import dbt.exceptions


class BaseSimpleSnapshotTest(DBTIntegrationTest):
Expand Down
1 change: 0 additions & 1 deletion tests/integration/sources_test/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import yaml

from dbt.exceptions import CompilationException
import dbt.tracking
import dbt.version
from dbt.events.functions import reset_metadata_vars
Expand Down
38 changes: 19 additions & 19 deletions tests/unit/test_bigquery_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def test_acquire_connection_oauth_no_project_validations(self, mock_open_connect
connection = adapter.acquire_connection('dummy')
self.assertEqual(connection.type, 'bigquery')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

except BaseException as e:
raise
Expand All @@ -173,8 +173,8 @@ def test_acquire_connection_oauth_validations(self, mock_open_connection):
connection = adapter.acquire_connection('dummy')
self.assertEqual(connection.type, 'bigquery')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

except BaseException as e:
raise
Expand All @@ -190,8 +190,8 @@ def test_acquire_connection_service_account_validations(self, mock_open_connecti
connection = adapter.acquire_connection('dummy')
self.assertEqual(connection.type, 'bigquery')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

except BaseException as e:
raise
Expand All @@ -207,8 +207,8 @@ def test_acquire_connection_oauth_token_validations(self, mock_open_connection):
connection = adapter.acquire_connection('dummy')
self.assertEqual(connection.type, 'bigquery')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

except BaseException as e:
raise
Expand All @@ -224,8 +224,8 @@ def test_acquire_connection_oauth_credentials_validations(self, mock_open_connec
connection = adapter.acquire_connection('dummy')
self.assertEqual(connection.type, 'bigquery')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

except BaseException as e:
raise
Expand All @@ -241,8 +241,8 @@ def test_acquire_connection_impersonated_service_account_validations(self, mock_
connection = adapter.acquire_connection('dummy')
self.assertEqual(connection.type, 'bigquery')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

except BaseException as e:
raise
Expand All @@ -259,8 +259,8 @@ def test_acquire_connection_priority(self, mock_open_connection):
self.assertEqual(connection.type, 'bigquery')
self.assertEqual(connection.credentials.priority, 'batch')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

mock_open_connection.assert_not_called()
connection.handle
Expand All @@ -274,8 +274,8 @@ def test_acquire_connection_maximum_bytes_billed(self, mock_open_connection):
self.assertEqual(connection.type, 'bigquery')
self.assertEqual(connection.credentials.maximum_bytes_billed, 0)

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))
except dbt.exceptions.DbtValidationError as e:
self.fail('got DbtValidationError: {}'.format(str(e)))

mock_open_connection.assert_not_called()
connection.handle
Expand Down Expand Up @@ -674,10 +674,10 @@ def test_copy_table_materialization_incremental(self):
def test_parse_partition_by(self):
adapter = self.get_adapter('oauth')

with self.assertRaises(dbt.exceptions.ValidationException):
with self.assertRaises(dbt.exceptions.DbtValidationError):
adapter.parse_partition_by("date(ts)")

with self.assertRaises(dbt.exceptions.ValidationException):
with self.assertRaises(dbt.exceptions.DbtValidationError):
adapter.parse_partition_by("ts")

self.assertEqual(
Expand Down Expand Up @@ -841,7 +841,7 @@ def test_parse_partition_by(self):
)

# Invalid, should raise an error
with self.assertRaises(dbt.exceptions.ValidationException):
with self.assertRaises(dbt.exceptions.DbtValidationError):
adapter.parse_partition_by({})

# passthrough
Expand Down

0 comments on commit 3ce88d7

Please sign in to comment.