Skip to content

Commit

Permalink
Return proper error message when empty profiles.yml is used for dbt p…
Browse files Browse the repository at this point in the history
…roject
  • Loading branch information
sumanau7 authored and Sumanau Sareen committed Apr 5, 2020
1 parent 6a26a5f commit 4f88355
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/dbt/config/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
{profiles_file}/profiles.yml
""".format(profiles_file=PROFILES_DIR)

EMPTY_PROFILE_MESSAGE = """
dbt cannot run because profiles.yml is empty for this dbt project.
"""


def read_profile(profiles_dir: str) -> Dict[str, Any]:
path = os.path.join(profiles_dir, 'profiles.yml')
Expand All @@ -52,7 +56,10 @@ def read_profile(profiles_dir: str) -> Dict[str, Any]:
if os.path.isfile(path):
try:
contents = load_file_contents(path, strip=False)
return load_yaml_text(contents)
yaml_content = load_yaml_text(contents)
if not yaml_content:
raise DbtProfileError(EMPTY_PROFILE_MESSAGE)
return yaml_content
except ValidationException as e:
msg = INVALID_PROFILE_MESSAGE.format(error_string=e)
raise ValidationException(msg) from e
Expand Down
10 changes: 10 additions & 0 deletions test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def write_profile(self, profile_data=None):
with open(self.profile_path('profiles.yml'), 'w') as fp:
yaml.dump(profile_data, fp)

def write_empty_profile(self):
with open(self.profile_path('profiles.yml'), 'w') as fp:
yaml.dump('', fp)


class TestProfile(BaseConfigTest):
def setUp(self):
Expand Down Expand Up @@ -530,6 +534,12 @@ def test_no_profile(self):
self.from_args(project_profile_name=None)
self.assertIn('no profile was specified', str(exc.exception))

def test_empty_profile(self):
self.write_empty_profile()
with self.assertRaises(dbt.exceptions.DbtProfileError) as exc:
self.from_args()
self.assertIn('profiles.yml is empty', str(exc.exception))


class TestProject(BaseConfigTest):
def setUp(self):
Expand Down

0 comments on commit 4f88355

Please sign in to comment.