Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to

## [Unreleased]

- Display the parse error message when `dbt parse` fails.

## [0.13.1] - 2025-07-29

- Fix filters being applied to wrong evaluables (#124)
Expand Down
4 changes: 2 additions & 2 deletions src/dbt_score/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def lint( # noqa: PLR0912, PLR0913, C901
)
ctx.exit(2)

except DbtParseException:
logger.error("dbt failed to parse project. Run `dbt parse` to investigate.")
except DbtParseException as exc:
logger.error(exc)
ctx.exit(2)

except Exception:
Expand Down
16 changes: 15 additions & 1 deletion src/dbt_score/dbt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ class DbtNotInstalledException(Exception):
class DbtParseException(Exception):
"""Raised when dbt parse fails."""

def __init__(self, root_cause: Exception | None = None):
"""Initialize the exception."""
super().__init__()
self.root_cause = root_cause

def __str__(self) -> str:
"""Return a string representation of the exception."""
if self.root_cause:
return f"dbt parse failed.\n\n{self.root_cause!s}"

return (
"dbt parse failed. Root cause not found. Please run `dbt parse` manually."
)


class DbtLsException(Exception):
"""Raised when dbt ls fails."""
Expand Down Expand Up @@ -61,7 +75,7 @@ def dbt_parse() -> "dbtRunnerResult":
result: "dbtRunnerResult" = dbtRunner().invoke(["parse"])

if not result.success:
raise DbtParseException("dbt parse failed.") from result.exception
raise DbtParseException(root_cause=result.exception)

return result

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def test_lint_dbt_parse_exception(caplog):
runner = CliRunner()

with patch("dbt_score.cli.dbt_parse") as mock_dbt_parse:
mock_dbt_parse.side_effect = DbtParseException("parsing error")
mock_dbt_parse.side_effect = DbtParseException()
result = runner.invoke(lint, ["-p"], catch_exceptions=False)
assert result.exit_code == 2
assert "dbt failed to parse project" in caplog.text
assert "dbt parse failed." in caplog.text


def test_lint_dbt_not_installed(caplog, manifest_path):
Expand Down