From 8c1ed5d993c7111afb7d0276a91c47dc79ece5cd Mon Sep 17 00:00:00 2001 From: saville Date: Wed, 20 Nov 2024 09:26:19 -0700 Subject: [PATCH 1/2] Handle container errors correctly --- buildrunner/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/buildrunner/__init__.py b/buildrunner/__init__.py index a5814929..85dfa01e 100644 --- a/buildrunner/__init__.py +++ b/buildrunner/__init__.py @@ -18,6 +18,7 @@ import sys import tarfile import tempfile +import traceback import types from typing import List, Optional @@ -35,6 +36,7 @@ from buildrunner.errors import ( BuildRunnerConfigurationError, BuildRunnerProcessingError, + BuildRunnerError, ) from buildrunner.steprunner import BuildStepRunner from buildrunner.docker.multiplatform_image_builder import MultiplatformImageBuilder @@ -470,13 +472,6 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many ) else: self.log.write("\nPush not requested\n") - - except BuildRunnerConfigurationError as brce: - exit_explanation = str(brce) - self.exit_code = os.EX_CONFIG - except BuildRunnerProcessingError as brpe: - exit_explanation = str(brpe) - self.exit_code = 1 except requests.exceptions.ConnectionError as rce: print(str(rce)) exit_explanation = ( @@ -486,6 +481,14 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many "remote PyPi server information is set correctly." ) self.exit_code = 1 + except BuildRunnerError as exc: + exit_explanation = str(exc) + self.exit_code = ( + os.EX_CONFIG if isinstance(exc, BuildRunnerConfigurationError) else 1 + ) + except Exception as exc: + exit_explanation = f"Encountered unhandled exception ({type(exc).__name__}) {traceback.format_exc()}" + self.exit_code = 1 finally: self._write_artifact_manifest() From f5a74972f02344aefc0ffd25d3087488903e4808 Mon Sep 17 00:00:00 2001 From: saville Date: Thu, 21 Nov 2024 11:44:48 -0700 Subject: [PATCH 2/2] Handle docker image not found errors --- buildrunner/__init__.py | 4 ++++ tests/test-files/test-docker-pull-failure.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/buildrunner/__init__.py b/buildrunner/__init__.py index 85dfa01e..37909e2b 100644 --- a/buildrunner/__init__.py +++ b/buildrunner/__init__.py @@ -472,6 +472,7 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many ) else: self.log.write("\nPush not requested\n") + except requests.exceptions.ConnectionError as rce: print(str(rce)) exit_explanation = ( @@ -481,6 +482,9 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many "remote PyPi server information is set correctly." ) self.exit_code = 1 + except ImageNotFound as inf: + exit_explanation = f"Image not found: {inf.explanation}" + self.exit_code = os.EX_CONFIG except BuildRunnerError as exc: exit_explanation = str(exc) self.exit_code = ( diff --git a/tests/test-files/test-docker-pull-failure.yaml b/tests/test-files/test-docker-pull-failure.yaml index 2dd1b630..d76b76a7 100644 --- a/tests/test-files/test-docker-pull-failure.yaml +++ b/tests/test-files/test-docker-pull-failure.yaml @@ -2,5 +2,5 @@ steps: use-bogus-image: run: - image: user1/buildrunner-test-multi-platform:bogus + image: user1/buildrunner-bogus-image:bogus cmd: echo "Hello World"