From efebe2286b1d6b1477e82cbff4e6e82f49cb4b77 Mon Sep 17 00:00:00 2001 From: David Moore Date: Tue, 1 Apr 2025 17:25:53 +1100 Subject: [PATCH 1/2] fix: stops process on service/website build errors Ensures the local cloud environment is stopped when service or website builds fail. This prevents the application from running with potentially broken or incomplete builds, improving reliability and preventing unexpected behavior. --- cmd/run.go | 23 +++++++++++++++++++++-- cmd/stack.go | 14 +++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index c624ede7..8266c62c 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -138,6 +138,11 @@ var runCmd = &cobra.Command{ // non-interactive environment for update := range allBuildUpdates { + if update.Status == project.ServiceBuildStatus_Error { + localCloud.Stop() + tui.CheckErr(fmt.Errorf("error building services")) + } + for _, line := range strings.Split(strings.TrimSuffix(update.Message, "\n"), "\n") { fmt.Printf("%s [%s]: %s\n", update.ServiceName, update.Status, line) } @@ -145,8 +150,12 @@ var runCmd = &cobra.Command{ } else { prog := teax.NewProgram(build.NewModel(allBuildUpdates, "Building Services")) // blocks but quits once the above updates channel is closed by the build process - _, err = prog.Run() + buildModel, err := prog.Run() tui.CheckErr(err) + if buildModel.(build.Model).Err != nil { + localCloud.Stop() + tui.CheckErr(fmt.Errorf("error building services")) + } } websiteBuildUpdates, err := proj.BuildWebsites(loadEnv) @@ -156,6 +165,11 @@ var runCmd = &cobra.Command{ if isNonInteractive() { fmt.Println("building project websites") for update := range websiteBuildUpdates { + if update.Status == project.ServiceBuildStatus_Error { + localCloud.Stop() + tui.CheckErr(fmt.Errorf("error building websites")) + } + for _, line := range strings.Split(strings.TrimSuffix(update.Message, "\n"), "\n") { fmt.Printf("%s [%s]: %s\n", update.ServiceName, update.Status, line) } @@ -163,8 +177,13 @@ var runCmd = &cobra.Command{ } else { prog := teax.NewProgram(build.NewModel(websiteBuildUpdates, "Building Websites")) // blocks but quits once the above updates channel is closed by the build process - _, err = prog.Run() + buildModel, err := prog.Run() tui.CheckErr(err) + + if buildModel.(build.Model).Err != nil { + localCloud.Stop() + tui.CheckErr(fmt.Errorf("error building websites")) + } } } diff --git a/cmd/stack.go b/cmd/stack.go index 2bc79f51..958d738f 100644 --- a/cmd/stack.go +++ b/cmd/stack.go @@ -198,6 +198,10 @@ var stackUpdateCmd = &cobra.Command{ // non-interactive environment for update := range allBuildUpdates { + if update.Status == project.ServiceBuildStatus_Error { + tui.CheckErr(fmt.Errorf("error building services")) + } + for _, line := range strings.Split(strings.TrimSuffix(update.Message, "\n"), "\n") { fmt.Printf("%s [%s]: %s\n", update.ServiceName, update.Status, line) } @@ -284,6 +288,10 @@ var stackUpdateCmd = &cobra.Command{ if isNonInteractive() { fmt.Println("building project websites") for update := range websiteBuildUpdates { + if update.Status == project.ServiceBuildStatus_Error { + tui.CheckErr(fmt.Errorf("error building websites")) + } + for _, line := range strings.Split(strings.TrimSuffix(update.Message, "\n"), "\n") { fmt.Printf("%s [%s]: %s\n", update.ServiceName, update.Status, line) } @@ -291,8 +299,12 @@ var stackUpdateCmd = &cobra.Command{ } else { prog := teax.NewProgram(build.NewModel(websiteBuildUpdates, "Building Websites")) // blocks but quits once the above updates channel is closed by the build process - _, err = prog.Run() + buildModel, err := prog.Run() tui.CheckErr(err) + + if buildModel.(build.Model).Err != nil { + tui.CheckErr(fmt.Errorf("error building websites")) + } } } From 34fc736ded05a3eb78ec4276f92abd4327e55d95 Mon Sep 17 00:00:00 2001 From: David Moore Date: Tue, 1 Apr 2025 17:26:08 +1100 Subject: [PATCH 2/2] Updates error message for image building --- cmd/debug.go | 2 +- cmd/stack.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/debug.go b/cmd/debug.go index df3e960f..9fe8e630 100644 --- a/cmd/debug.go +++ b/cmd/debug.go @@ -147,7 +147,7 @@ var specCmd = &cobra.Command{ buildModel, err := prog.Run() tui.CheckErr(err) if buildModel.(build.Model).Err != nil { - tui.CheckErr(fmt.Errorf("error building services")) + tui.CheckErr(fmt.Errorf("error building migration images")) } } } diff --git a/cmd/stack.go b/cmd/stack.go index 958d738f..990a06bd 100644 --- a/cmd/stack.go +++ b/cmd/stack.go @@ -276,7 +276,7 @@ var stackUpdateCmd = &cobra.Command{ buildModel, err := prog.Run() tui.CheckErr(err) if buildModel.(build.Model).Err != nil { - tui.CheckErr(fmt.Errorf("error building services")) + tui.CheckErr(fmt.Errorf("error building migration images")) } } }