77import os
88import subprocess
99import sys
10+ from dataclasses import dataclass
1011from enum import Enum
1112from pathlib import Path
1213
1920 PYTHON_CONNECTOR_DOCKERFILE_TEMPLATE ,
2021)
2122
23+
24+ @dataclass (kw_only = True )
25+ class ConnectorImageBuildError (Exception ):
26+ """Custom exception for Docker build errors."""
27+
28+ error_text : str
29+ build_args : list [str ]
30+
31+ def __str__ (self ) -> str :
32+ return "\n " .join ([
33+ f"ConnectorImageBuildError: Could not build image." ,
34+ f"Build args: { self .build_args } " ,
35+ f"Error text: { self .error_text } " ,
36+ ])
37+
38+
2239logger = logging .getLogger (__name__ )
2340
2441
@@ -40,6 +57,8 @@ def _build_image(
4057 """Build a Docker image for the specified architecture.
4158
4259 Returns the tag of the built image.
60+
61+ Raises: ConnectorImageBuildError if the build fails.
4362 """
4463 docker_args : list [str ] = [
4564 "docker" ,
@@ -71,9 +90,11 @@ def _build_image(
7190 docker_args ,
7291 )
7392 except subprocess .CalledProcessError as e :
74- print (f"ERROR: Failed to build image using Docker args: { docker_args } " )
75- exit (1 )
76- raise
93+ raise ConnectorImageBuildError (
94+ error_text = e .stderr ,
95+ build_args = docker_args ,
96+ ) from e
97+
7798 return tag
7899
79100
@@ -126,6 +147,10 @@ def build_connector_image(
126147 architecture will be used for the same-named tag. Both AMD64 and ARM64
127148 images will be built, with the suffixes '-amd64' and '-arm64'.
128149 no_verify: If True, skip verification of the built image.
150+
151+ Raises:
152+ ValueError: If the connector build options are not defined in metadata.yaml.
153+ ConnectorImageBuildError: If the build fails.
129154 """
130155 connector_kebab_name = connector_name
131156 connector_snake_name = connector_kebab_name .replace ("-" , "_" )
0 commit comments