This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new f81ba62 Include exit code in AirflowException str when BashOperator
fails. (#17151)
f81ba62 is described below
commit f81ba62dbfd03bdb66f7af0e9bec55c577e84d38
Author: ConnorLin <[email protected]>
AuthorDate: Sun Jul 25 12:51:36 2021 -0400
Include exit code in AirflowException str when BashOperator fails. (#17151)
---
airflow/operators/bash.py | 4 +++-
tests/operators/test_bash.py | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/airflow/operators/bash.py b/airflow/operators/bash.py
index 44e1aa2..c32cd5d 100644
--- a/airflow/operators/bash.py
+++ b/airflow/operators/bash.py
@@ -173,7 +173,9 @@ class BashOperator(BaseOperator):
if self.skip_exit_code is not None and result.exit_code ==
self.skip_exit_code:
raise AirflowSkipException(f"Bash command returned exit code
{self.skip_exit_code}. Skipping.")
elif result.exit_code != 0:
- raise AirflowException('Bash command failed. The command returned
a non-zero exit code.')
+ raise AirflowException(
+ f'Bash command failed. The command returned a non-zero exit
code {result.exit_code}.'
+ )
return result.output
def on_kill(self) -> None:
diff --git a/tests/operators/test_bash.py b/tests/operators/test_bash.py
index 3dc9aa4..9810272 100644
--- a/tests/operators/test_bash.py
+++ b/tests/operators/test_bash.py
@@ -101,7 +101,7 @@ class TestBashOperator(unittest.TestCase):
def test_raise_exception_on_non_zero_exit_code(self):
bash_operator = BashOperator(bash_command='exit 42',
task_id='test_return_value', dag=None)
with pytest.raises(
- AirflowException, match="Bash command failed\\. The command
returned a non-zero exit code\\."
+ AirflowException, match="Bash command failed\\. The command
returned a non-zero exit code 42\\."
):
bash_operator.execute(context={})
@@ -119,7 +119,7 @@ class TestBashOperator(unittest.TestCase):
def test_command_not_found(self):
with pytest.raises(
- AirflowException, match="Bash command failed\\. The command
returned a non-zero exit code\\."
+ AirflowException, match="Bash command failed\\. The command
returned a non-zero exit code 127\\."
):
BashOperator(task_id='abc', bash_command='set -e;
something-that-isnt-on-path').execute({})