Skip to content
Open
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
1 change: 1 addition & 0 deletions newsfragments/use_podman_compose_error_for_build.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use `PodmanComposeError` instead of generic `OSError` when build-related validation fails.
8 changes: 5 additions & 3 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3567,7 +3567,9 @@ def container_to_build_args(
dockerfile_inline = str(dockerfile_inline)
# Error if both `dockerfile_inline` and `dockerfile` are set
if dockerfile and dockerfile_inline:
raise OSError("dockerfile_inline and dockerfile can't be used simultaneously")
raise PodmanComposeError(
"dockerfile_inline and dockerfile can't be used simultaneously"
)
dockerfile = tempfile.NamedTemporaryFile(delete=False, suffix=".containerfile")
dockerfile.write(dockerfile_inline.encode())
dockerfile.close()
Expand Down Expand Up @@ -3608,8 +3610,8 @@ def cleanup_temp_dockfile() -> None:
else:
if custom_dockerfile_given:
# custom dockerfile name was also not found in the file system
raise OSError(f"Dockerfile not found in {dockerfile}")
raise OSError(f"Dockerfile not found in {ctx}")
raise PodmanComposeError(f"Dockerfile not found in {dockerfile}")
raise PodmanComposeError(f"Dockerfile not found in {ctx}")

elif dockerfile:
build_args.extend(["-f", dockerfile])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_dockerfile_does_not_exist(self):
result = '\n'.join(error.splitlines()[-1:])

expected_path = os.path.join(os.path.dirname(__file__), "context_no_file")
expected = f'OSError: Dockerfile not found in {expected_path}'
expected = f'Error: Dockerfile not found in {expected_path}'

self.assertEqual(expected, result)

Expand All @@ -64,6 +64,6 @@ def test_custom_dockerfile_does_not_exist(self):
result = '\n'.join(error.splitlines()[-1:])

expected_path = os.path.join(os.path.dirname(__file__), "context_no_file/Dockerfile-alt")
expected = f'OSError: Dockerfile not found in {expected_path}'
expected = f'Error: Dockerfile not found in {expected_path}'

self.assertEqual(expected, result)
3 changes: 2 additions & 1 deletion tests/unit/test_container_to_build_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest
from unittest import mock

from podman_compose import PodmanComposeError
from podman_compose import container_to_build_args


Expand Down Expand Up @@ -223,7 +224,7 @@ def test_context_invalid_git_url_git_is_not_prefix(self):
cnt['build']['context'] = "not_prefix://github.com/test_repo"
args = get_minimal_args()

with self.assertRaises(OSError):
with self.assertRaises(PodmanComposeError):
container_to_build_args(c, cnt, args, lambda path: False)

def test_build_ssh_absolute_path(self):
Expand Down