Skip to content

Commit dcbc7cc

Browse files
committed
improve err handling for connector image build
1 parent 53dbe55 commit dcbc7cc

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

airbyte_cdk/cli/airbyte_cdk/_image.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from airbyte_cdk.cli.airbyte_cdk._util import resolve_connector_name_and_directory
1414
from airbyte_cdk.models.connector_metadata import MetadataFile
1515
from airbyte_cdk.utils.docker import (
16+
ConnectorImageBuildError,
1617
build_connector_image,
1718
verify_docker_installation,
1819
)
@@ -73,13 +74,20 @@ def build(
7374
)
7475
sys.exit(1)
7576
click.echo(f"Building Image for Connector: {metadata.data.dockerRepository}:{tag}")
76-
build_connector_image(
77-
connector_directory=connector_directory,
78-
connector_name=connector_name,
79-
metadata=metadata,
80-
tag=tag,
81-
no_verify=no_verify,
82-
)
77+
try:
78+
build_connector_image(
79+
connector_directory=connector_directory,
80+
connector_name=connector_name,
81+
metadata=metadata,
82+
tag=tag,
83+
no_verify=no_verify,
84+
)
85+
except ConnectorImageBuildError as e:
86+
click.echo(
87+
f"Error building connector image: {e!s}",
88+
err=True,
89+
)
90+
sys.exit(1)
8391

8492

8593
__all__ = [

airbyte_cdk/utils/docker.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import subprocess
99
import sys
10+
from dataclasses import dataclass
1011
from enum import Enum
1112
from pathlib import Path
1213

@@ -19,6 +20,22 @@
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+
2239
logger = 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

Comments
 (0)