Repository: dbt-labs/dbt-redshift (python)

Issue:
[CT-1681] Replace deprecated exception functions
`dbt-core` has deprecated functions to raise exceptions in favor of directly raising the exceptions. Nothing should be broken (yet) and the functions still raise as expected but they also will log a deprecation warning (pending https://github.com/dbt-labs/dbt-core/pull/6413). It would be good to resolve these deprecation messages before the 1.4 rc.

There are a lot of deprecated function so it's easier to search for `dbt.exceptions` and look at each callsite to determine if it's using a function or already directly raising an exception. Then replace anywhere using functions with directly raising an exception.

We can create new exceptions in `dbt-core` to raise or the adapters could start to own their own exceptions within the adapter code base that inherit from exceptions in `dbt-core`.

For examples, see [`dbt-core` PR](https://github.com/dbt-labs/dbt-core/pull/6347) that replaced all functions with raises.

Pull request:
Rename exceptions
resolves #250 

### Description

Replace exception functions and rename exceptions. Currently point to a branch of core for testing.

### Checklist

- [ ] I have read [the contributing guide](https://github.com/dbt-labs/dbt-redshift/blob/main/CONTRIBUTING.md) and understand what's expected of me
- [ ] I have signed the [CLA](https://docs.getdbt.com/docs/contributor-license-agreements)
- [ ] I have run this code in development and it appears to resolve the stated issue
- [ ] This PR includes tests, or tests are not required/relevant for this PR
- [ ] I have [opened an issue to add/update docs](https://github.com/dbt-labs/docs.getdbt.com/issues/new/choose), or docs changes are not required/relevant for this PR
- [ ] I have run `changie new` to [create a changelog entry](https://github.com/dbt-labs/dbt-redshift/blob/main/CONTRIBUTING.md#Adding-CHANGELOG-Entry)


Patch:
diff --git a/.changes/unreleased/Under the Hood-20230110-100647.yaml b/.changes/unreleased/Under the Hood-20230110-100647.yaml
new file mode 100644
index 00000000..a0dad2ab
--- /dev/null
+++ b/.changes/unreleased/Under the Hood-20230110-100647.yaml
@@ -0,0 +1,7 @@
+kind: Under the Hood
+body: Rename exceptions to match dbt-core
+time: 2023-01-10T10:06:47.570088-06:00
+custom:
+  Author: emmyoop
+  Issue: "250"
+  PR: "258"
diff --git a/dbt/adapters/redshift/connections.py b/dbt/adapters/redshift/connections.py
index be4d626d..a1335395 100644
--- a/dbt/adapters/redshift/connections.py
+++ b/dbt/adapters/redshift/connections.py
@@ -114,7 +114,7 @@ class RedshiftConnectionManager(PostgresConnectionManager):
             )
 
         except boto_client.exceptions.ClientError as e:
-            raise dbt.exceptions.FailedToConnectException(
+            raise dbt.exceptions.FailedToConnectError(
                 "Unable to get temporary Redshift cluster credentials: {}".format(e)
             )
 
@@ -127,7 +127,7 @@ class RedshiftConnectionManager(PostgresConnectionManager):
         iam_duration_s = credentials.iam_duration_seconds
 
         if not cluster_id:
-            raise dbt.exceptions.FailedToConnectException(
+            raise dbt.exceptions.FailedToConnectError(
                 "'cluster_id' must be provided in profile if IAM " "authentication method selected"
             )
 
@@ -156,7 +156,7 @@ class RedshiftConnectionManager(PostgresConnectionManager):
             # this requirement is really annoying to encode into json schema,
             # so validate it here
             if credentials.password is None:
-                raise dbt.exceptions.FailedToConnectException(
+                raise dbt.exceptions.FailedToConnectError(
                     "'password' field is required for 'database' credentials"
                 )
             return credentials
@@ -166,6 +166,6 @@ class RedshiftConnectionManager(PostgresConnectionManager):
             return cls.get_tmp_iam_cluster_credentials(credentials)
 
         else:
-            raise dbt.exceptions.FailedToConnectException(
+            raise dbt.exceptions.FailedToConnectError(
                 "Invalid 'method' in profile: '{}'".format(method)
             )
diff --git a/dbt/adapters/redshift/impl.py b/dbt/adapters/redshift/impl.py
index 206185f5..4ece2ff5 100644
--- a/dbt/adapters/redshift/impl.py
+++ b/dbt/adapters/redshift/impl.py
@@ -72,7 +72,7 @@ class RedshiftAdapter(PostgresAdapter, SQLAdapter):
         ra3_node = self.config.credentials.ra3_node
 
         if database.lower() != expected.lower() and not ra3_node:
-            raise dbt.exceptions.NotImplementedException(
+            raise dbt.exceptions.NotImplementedError(
                 "Cross-db references allowed only in RA3.* node. ({} vs {})".format(
                     database, expected
                 )
@@ -85,8 +85,8 @@ class RedshiftAdapter(PostgresAdapter, SQLAdapter):
         schemas = super(SQLAdapter, self)._get_catalog_schemas(manifest)
         try:
             return schemas.flatten(allow_multiple_databases=self.config.credentials.ra3_node)
-        except dbt.exceptions.RuntimeException as exc:
-            dbt.exceptions.raise_compiler_error(
+        except dbt.exceptions.DbtRuntimeError as exc:
+            raise dbt.exceptions.CompilationError(
                 "Cross-db references allowed only in {} RA3.* node. Got {}".format(
                     self.type(), exc.msg
                 )


Test patch:
diff --git a/tests/unit/test_context.py b/tests/unit/test_context.py
index 5b975d02..5170fcfb 100644
--- a/tests/unit/test_context.py
+++ b/tests/unit/test_context.py
@@ -212,7 +212,7 @@ def test_resolve_specific(config, manifest_extended, redshift_adapter, get_inclu
     ctx['adapter'].config.dispatch
 
     # macro_a exists, but default__macro_a and redshift__macro_a do not
-    with pytest.raises(dbt.exceptions.CompilationException):
+    with pytest.raises(dbt.exceptions.CompilationError):
         ctx['adapter'].dispatch('macro_a').macro
 
     # root namespace is always preferred, unless search order is explicitly defined in 'dispatch' config
diff --git a/tests/unit/test_redshift_adapter.py b/tests/unit/test_redshift_adapter.py
index 33c3dc1a..92fd9cbd 100644
--- a/tests/unit/test_redshift_adapter.py
+++ b/tests/unit/test_redshift_adapter.py
@@ -10,7 +10,7 @@ from dbt.adapters.redshift import (
     Plugin as RedshiftPlugin,
 )
 from dbt.clients import agate_helper
-from dbt.exceptions import FailedToConnectException
+from dbt.exceptions import FailedToConnectError
 
 from .utils import config_from_parts_or_dicts, mock_connection, TestAdapterConversions, inject_adapter
 
@@ -115,7 +115,7 @@ class TestRedshiftAdapter(unittest.TestCase):
         # we have to set method this way, otherwise it won't validate
         self.config.credentials.method = 'badmethod'
 
-        with self.assertRaises(FailedToConnectException) as context:
+        with self.assertRaises(FailedToConnectError) as context:
             with mock.patch.object(
                     RedshiftAdapter.ConnectionManager,
                     'fetch_cluster_credentials',
@@ -127,7 +127,7 @@ class TestRedshiftAdapter(unittest.TestCase):
 
     def test_invalid_iam_no_cluster_id(self):
         self.config.credentials = self.config.credentials.replace(method='iam')
-        with self.assertRaises(FailedToConnectException) as context:
+        with self.assertRaises(FailedToConnectError) as context:
             with mock.patch.object(
                     RedshiftAdapter.ConnectionManager,
                     'fetch_cluster_credentials',