Skip to content

Commit 05d4e99

Browse files
authored
Merge pull request #176 from bluesliverx/main
Handle container errors correctly
2 parents a6d9d42 + f5a7497 commit 05d4e99

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

buildrunner/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sys
1919
import tarfile
2020
import tempfile
21+
import traceback
2122
import types
2223
from typing import List, Optional
2324

@@ -35,6 +36,7 @@
3536
from buildrunner.errors import (
3637
BuildRunnerConfigurationError,
3738
BuildRunnerProcessingError,
39+
BuildRunnerError,
3840
)
3941
from buildrunner.steprunner import BuildStepRunner
4042
from buildrunner.docker.multiplatform_image_builder import MultiplatformImageBuilder
@@ -471,12 +473,6 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many
471473
else:
472474
self.log.write("\nPush not requested\n")
473475

474-
except BuildRunnerConfigurationError as brce:
475-
exit_explanation = str(brce)
476-
self.exit_code = os.EX_CONFIG
477-
except BuildRunnerProcessingError as brpe:
478-
exit_explanation = str(brpe)
479-
self.exit_code = 1
480476
except requests.exceptions.ConnectionError as rce:
481477
print(str(rce))
482478
exit_explanation = (
@@ -486,6 +482,17 @@ def run(self): # pylint: disable=too-many-statements,too-many-branches,too-many
486482
"remote PyPi server information is set correctly."
487483
)
488484
self.exit_code = 1
485+
except ImageNotFound as inf:
486+
exit_explanation = f"Image not found: {inf.explanation}"
487+
self.exit_code = os.EX_CONFIG
488+
except BuildRunnerError as exc:
489+
exit_explanation = str(exc)
490+
self.exit_code = (
491+
os.EX_CONFIG if isinstance(exc, BuildRunnerConfigurationError) else 1
492+
)
493+
except Exception as exc:
494+
exit_explanation = f"Encountered unhandled exception ({type(exc).__name__}) {traceback.format_exc()}"
495+
self.exit_code = 1
489496

490497
finally:
491498
self._write_artifact_manifest()

tests/test-files/test-docker-pull-failure.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
steps:
33
use-bogus-image:
44
run:
5-
image: user1/buildrunner-test-multi-platform:bogus
5+
image: user1/buildrunner-bogus-image:bogus
66
cmd: echo "Hello World"

0 commit comments

Comments
 (0)