Skip to content

Commit

Permalink
more conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed Dec 5, 2022
1 parent 24b2ff5 commit a25bfb9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
4 changes: 2 additions & 2 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from dbt.exceptions import (
raise_compiler_error,
invalid_type_error,
get_relation_returned_multiple_results,
InternalException,
NotImplementedException,
RelationReturnedMultipleResults,
RuntimeException,
UnexpectedNull,
UnexpectedNonTimestamp,
Expand Down Expand Up @@ -776,7 +776,7 @@ def get_relation(self, database: str, schema: str, identifier: str) -> Optional[
"schema": schema,
"database": database,
}
get_relation_returned_multiple_results(kwargs, matches)
raise RelationReturnedMultipleResults(kwargs, matches)

elif matches:
return matches[0]
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/clients/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def make_symlink(source: str, link_path: str) -> None:
Create a symlink at `link_path` referring to `source`.
"""
if not supports_symlinks():
dbt.exceptions.system_error("create a symbolic link")
# TODO: why not import these at top?
raise dbt.exceptions.SymbolicLinkError()

os.symlink(source, link_path)

Expand Down
72 changes: 49 additions & 23 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,24 +689,19 @@ def invalid_materialization_argument(name, argument):
)


def system_error(operation_name):
raise_compiler_error(
"dbt encountered an error when attempting to {}. "
"If this error persists, please create an issue at: \n\n"
"https://github.com/dbt-labs/dbt-core".format(operation_name)
)


def multiple_matching_relations(kwargs, matches):
raise_compiler_error(
"get_relation returned more than one relation with the given args. "
"Please specify a database or schema to narrow down the result set."
"\n{}\n\n{}".format(kwargs, matches)
)
# client level exceptions
class SymbolicLinkError(CompilationException):
def __init__(self):
super().__init__(self.get_message())

def get_message(self) -> str:
msg = (
"dbt encountered an error when attempting to create a symbolic link. "
"If this error persists, please create an issue at: \n\n"
"https://github.com/dbt-labs/dbt-core"
)

def get_relation_returned_multiple_results(kwargs, matches):
multiple_matching_relations(kwargs, matches)
return msg


# context level exceptions
Expand Down Expand Up @@ -798,6 +793,21 @@ def get_message(self) -> str:


# adapters exceptions
class RelationReturnedMultipleResults(CompilationException):
def __init__(self, kwargs, matches):
self.kwargs = kwargs
self.matches = matches
super().__init__(self.get_message())

def get_message(self) -> str:
msg = (
"get_relation returned more than one relation with the given args. "
"Please specify a database or schema to narrow down the result set."
f"\n{self.kwargs}\n\n{self.matches}"
)
return msg


class ApproximateMatch(CompilationException):
def __init__(self, target, relation):
self.target = target
Expand Down Expand Up @@ -1283,21 +1293,37 @@ def approximate_relation_match(target, relation):
raise ApproximateMatch(target, relation)


def get_relation_returned_multiple_results(kwargs, matches):
raise RelationReturnedMultipleResults(kwargs, matches)


def system_error(operation_name):
# Note: This was converted for core to use SymbolicLinkError because it's the only way it was used. Maintaining flexibility here for now.
msg = (
f"dbt encountered an error when attempting to {operation_name}. "
"If this error persists, please create an issue at: \n\n"
"https://github.com/dbt-labs/dbt-core"
)
raise CompilationException(msg)


# These are the exceptions functions that were not called within dbt-core but will remain here but deprecated to give a chance to rework
# TODO: is this valid? Should I create a special exception class for this?
def raise_unrecognized_credentials_type(typename, supported_types):
raise_compiler_error(
'Unrecognized credentials type "{}" - supported types are ({})'.format(
typename, ", ".join('"{}"'.format(t) for t in supported_types)
)
msg = 'Unrecognized credentials type "{}" - supported types are ({})'.format(
typename, ", ".join('"{}"'.format(t) for t in supported_types)
)
raise CompilationException(msg)


def raise_patch_targets_not_found(patches):
patch_list = "\n\t".join(
"model {} (referenced in path {})".format(p.name, p.original_file_path)
for p in patches.values()
)
raise_compiler_error(
"dbt could not find models for the following patches:\n\t{}".format(patch_list)
)
msg = f"dbt could not find models for the following patches:\n\t{patch_list}"
raise CompilationException(msg)


def multiple_matching_relations(kwargs, matches):
raise RelationReturnedMultipleResults(kwargs, matches)

0 comments on commit a25bfb9

Please sign in to comment.