Skip to content

Commit

Permalink
Improve dbt ls error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana committed Jul 14, 2023
1 parent e72946e commit 2d268e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 11 additions & 8 deletions cosmos/dbt/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def load(self, method=LoadMode.AUTOMATIC, execution_mode="local"):
elif execution_mode in ("local", "virtualenv"):
try:
self.load_via_dbt_ls()
return
except FileNotFoundError:
self.load_via_custom_parser()
finally:
return

Check warning on line 82 in cosmos/dbt/graph.py

View check run for this annotation

Codecov / codecov/patch

cosmos/dbt/graph.py#L80-L82

Added lines #L80 - L82 were not covered by tests
else:
self.load_via_custom_parser()
Expand All @@ -96,19 +96,22 @@ def load_via_dbt_ls(self):
command.extend(["--exclude", *self.exclude])
if self.select:
command.extend(["--select", *self.select])

logger.info(f"Running command: {command}")
try:
process = Popen(command, stdout=PIPE, stderr=PIPE, cwd=self.project.dir)
process = Popen(command, stdout=PIPE, stderr=PIPE, cwd=self.project.dir, universal_newlines=True)
except FileNotFoundError as exception:
raise CosmosLoadDbtException(f"Unable to run the command {command} due to the error:\n{exception}")
raise CosmosLoadDbtException(f"Unable to run the command due to the error:\n{exception}")

Check warning on line 103 in cosmos/dbt/graph.py

View check run for this annotation

Codecov / codecov/patch

cosmos/dbt/graph.py#L102-L103

Added lines #L102 - L103 were not covered by tests

stdout, stderr = process.communicate()
# TODO: cover this with test:
if stderr:
raise CosmosLoadDbtException(f"Unable to run the command {command} due to the error:\n{stderr}")

logger.debug(f"Output: {stdout}")

if stderr or "Runtime Error" in stdout:
details = stderr or stdout
raise CosmosLoadDbtException(f"Unable to run the command due to the error:\n{details}")

Check warning on line 111 in cosmos/dbt/graph.py

View check run for this annotation

Codecov / codecov/patch

cosmos/dbt/graph.py#L110-L111

Added lines #L110 - L111 were not covered by tests

nodes = {}
for line in stdout.decode().split("\n"):
for line in stdout.split("\n"):
try:
node_dict = json.loads(line.strip())
except json.decoder.JSONDecodeError:
Expand Down
4 changes: 3 additions & 1 deletion cosmos/dbt/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ def update_profile_path(self):
self.profile_path = self.pipeline_dir / "profiles.yml"
if not self.profile_path.exists():
with open(self.profile_path, "w") as fp:
profile_content = {self.name: {"target": "dev"}, "output": {"dev": {}}}
profile_content = {

Check warning on line 43 in cosmos/dbt/project.py

View check run for this annotation

Codecov / codecov/patch

cosmos/dbt/project.py#L42-L43

Added lines #L42 - L43 were not covered by tests
self.name: {"target": "dev", "outputs": {"dev": {"type": "sqlite", "database": "/tmp/dummy.db"}}}
}
yaml.dump(profile_content, fp)

Check warning on line 46 in cosmos/dbt/project.py

View check run for this annotation

Codecov / codecov/patch

cosmos/dbt/project.py#L46

Added line #L46 was not covered by tests

0 comments on commit 2d268e7

Please sign in to comment.