From 8d0af28542a4633d1650a87ec397b895d5610300 Mon Sep 17 00:00:00 2001 From: Aucoto Date: Mon, 26 Oct 2026 19:31:06 +0800 Subject: [PATCH] fix(compose): name the compose file in processFile errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createLayers and processExtends return processFile errors unwrapped, so a failure in any of the project's compose files — the extended ones included — reaches the user with no hint of which file to fix. Wrap the two call sites with the file name. Signed-off-by: Aucoto --- pkg/compose/publish.go | 4 ++-- pkg/compose/publish_test.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/compose/publish.go b/pkg/compose/publish.go index b3616030dfe..55ebe8cf485 100644 --- a/pkg/compose/publish.go +++ b/pkg/compose/publish.go @@ -199,7 +199,7 @@ func (s *composeService) createLayers(ctx context.Context, project *types.Projec for _, file := range project.ComposeFiles { data, err := processFile(ctx, file, project, extFiles, envFiles) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to process compose file %s: %w", file, err) } layerDescriptor := oci.DescriptorForComposeFile(file, data) @@ -235,7 +235,7 @@ func processExtends(ctx context.Context, project *types.Project, extFiles map[st for xf, hash := range extFiles { data, err := processFile(ctx, xf, project, moreExtFiles, envFiles) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to process compose file %s: %w", xf, err) } layerDescriptor := oci.DescriptorForComposeFile(hash, data) diff --git a/pkg/compose/publish_test.go b/pkg/compose/publish_test.go index 79b3884da57..841919fc466 100644 --- a/pkg/compose/publish_test.go +++ b/pkg/compose/publish_test.go @@ -112,6 +112,26 @@ services: }, cmp.Ignore())) } +// a processFile failure must say which file it came from: a project can +// carry many compose files and its extends references add more, so an +// unattributed error leaves the user guessing which one to fix +func Test_createLayers_error_includes_file_name(t *testing.T) { + project := &types.Project{Name: "test", WorkingDir: t.TempDir()} + project.ComposeFiles = []string{filepath.Join(t.TempDir(), "missing.yaml")} + + service := &composeService{} + _, err := service.createLayers(t.Context(), project, api.PublishOptions{}) + assert.ErrorContains(t, err, "failed to process compose file") + assert.ErrorContains(t, err, "missing.yaml") +} + +func Test_processExtends_error_includes_file_name(t *testing.T) { + extFile := filepath.Join(t.TempDir(), "missing.yaml") + _, err := processExtends(t.Context(), &types.Project{Name: "test"}, map[string]string{extFile: "deadbeef"}) + assert.ErrorContains(t, err, "failed to process compose file") + assert.ErrorContains(t, err, "missing.yaml") +} + func Test_preChecks_sensitive_data_detected_decline(t *testing.T) { dir := t.TempDir() envPath := dir + "/secrets.env"