From e24b825c1842568dc2714195584aae6d3cdaf290 Mon Sep 17 00:00:00 2001 From: Cliff Lau Date: Tue, 19 Sep 2023 09:55:39 +0800 Subject: [PATCH] chore: raise CosmosLoadDbtException when returncode is not zero --- cosmos/dbt/graph.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cosmos/dbt/graph.py b/cosmos/dbt/graph.py index 07a55ad79..71826aba0 100644 --- a/cosmos/dbt/graph.py +++ b/cosmos/dbt/graph.py @@ -193,9 +193,10 @@ def load_via_dbt_ls(self) -> None: env=env, ) stdout, stderr = process.communicate() + returncode = process.returncode logger.debug("dbt deps output: %s", stdout) - if stderr or "Error" in stdout: + if returncode: details = stderr or stdout raise CosmosLoadDbtException(f"Unable to run dbt deps command due to the error:\n{details}") @@ -222,6 +223,7 @@ def load_via_dbt_ls(self) -> None: ) stdout, stderr = process.communicate() + returncode = process.returncode logger.debug("dbt output: %s", stdout) log_filepath = log_dir / DBT_LOG_FILENAME @@ -231,14 +233,14 @@ def load_via_dbt_ls(self) -> None: for line in logfile: logger.debug(line.strip()) - if stderr or "Error" in stdout: - if 'Run "dbt deps" to install package dependencies' in stdout: - raise CosmosLoadDbtException( - "Unable to run dbt ls command due to missing dbt_packages. Set render_config.dbt_deps=True." - ) - else: - details = stderr or stdout - raise CosmosLoadDbtException(f"Unable to run dbt ls command due to the error:\n{details}") + if 'Run "dbt deps" to install package dependencies' in stdout: + raise CosmosLoadDbtException( + "Unable to run dbt ls command due to missing dbt_packages. Set render_config.dbt_deps=True." + ) + + if returncode: + details = stderr or stdout + raise CosmosLoadDbtException(f"Unable to run dbt ls command due to the error:\n{details}") nodes = {} for line in stdout.split("\n"):