From 36ff2e8233f286af5d59db8d943ba1b93d4f3036 Mon Sep 17 00:00:00 2001 From: puneeth_aditya_5656 Date: Tue, 5 May 2026 17:39:54 +0530 Subject: [PATCH] fix image pull stream error handling Signed-off-by: puneeth_aditya_5656 --- pkg/connectors/container_client.go | 12 ++++++++- pkg/connectors/container_client_test.go | 35 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 pkg/connectors/container_client_test.go diff --git a/pkg/connectors/container_client.go b/pkg/connectors/container_client.go index 84f5472..f26095b 100644 --- a/pkg/connectors/container_client.go +++ b/pkg/connectors/container_client.go @@ -112,7 +112,9 @@ func (cli *containerClient) CreateContainer(opts ContainerOpts) (string, error) return "", err } defer out.Close() - io.Copy(os.Stdout, out) + if err := copyImagePullOutput(out); err != nil { + return "", err + } resp, err := cli.cli.ContainerCreate( ctx, @@ -148,3 +150,11 @@ func (cli *containerClient) StopContainer(containerId string) error { func (cli *containerClient) CloseClient() error { return cli.cli.Close() } + +func copyImagePullOutput(out io.Reader) error { + _, err := io.Copy(os.Stdout, out) + if err != nil { + return fmt.Errorf("failed to read image pull output: %w", err) + } + return nil +} diff --git a/pkg/connectors/container_client_test.go b/pkg/connectors/container_client_test.go new file mode 100644 index 0000000..e155d87 --- /dev/null +++ b/pkg/connectors/container_client_test.go @@ -0,0 +1,35 @@ +package connectors + +import ( + "errors" + "io" + "strings" + "testing" +) + +type failingReader struct{} + +func (f failingReader) Read(p []byte) (int, error) { + return 0, errors.New("read failed") +} + +func TestCopyImagePullOutputReturnsReadError(t *testing.T) { + err := copyImagePullOutput(failingReader{}) + + if err == nil { + t.Fatal("expected error") + } + if !strings.Contains(err.Error(), "failed to read image pull output") { + t.Fatalf("unexpected error: %v", err) + } +} + +func TestCopyImagePullOutputSucceeds(t *testing.T) { + err := copyImagePullOutput(strings.NewReader("")) + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } +} + +var _ io.Reader = failingReader{}