From 6aa84cef0bf4762bb0b77059e2712d9c2416d628 Mon Sep 17 00:00:00 2001 From: Rhys Koedijk Date: Fri, 1 Nov 2024 02:30:26 +1300 Subject: [PATCH] Always write the update output file, even on container failure (#376) * Always write update output file, even on container failure * Fix typo * Tidy code --- internal/infra/run.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/infra/run.go b/internal/infra/run.go index c2f863f..faa644f 100644 --- a/internal/infra/run.go +++ b/internal/infra/run.go @@ -131,12 +131,15 @@ func Run(params RunParams) error { if params.ApiUrl == "" { params.ApiUrl = fmt.Sprintf("http://host.docker.internal:%v", api.Port()) } - if err := runContainers(ctx, params); err != nil { - return err - } + + // run the containers, but don't return the error until AFTER the output is generated. + // this ensures that the output is always written in the scenario where there are multiple outputs, + // some that succeed and some that fail; we still want to see the output of the successful ones. + runContainersErr := runContainers(ctx, params) api.Complete() + // write the output to a file output, err := generateOutput(params, api, outFile) if err != nil { return err @@ -146,7 +149,7 @@ func Run(params RunParams) error { return diff(params, outFile, output) } - return nil + return runContainersErr } func generateOutput(params RunParams, api *server.API, outFile *os.File) ([]byte, error) {