From 762eaa8e3226f6ba540cdcee4f7fb77b2b931d25 Mon Sep 17 00:00:00 2001 From: Jeff Haynie Date: Tue, 29 Apr 2025 15:40:40 -0500 Subject: [PATCH] DevMode: when build failure after initial start, dont fail just print the error and continue --- cmd/dev.go | 17 +++++++++++++---- internal/bundler/bundler.go | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/dev.go b/cmd/dev.go index c019de33..f7e6edac 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -107,27 +107,36 @@ Examples: errsystem.New(errsystem.ErrInvalidConfiguration, err, errsystem.WithContextMessage("Failed to run project")).ShowErrorAndExit() } - build := func() { + build := func(initial bool) { started := time.Now() + var ok bool tui.ShowSpinner("Building project ...", func() { if err := bundler.Bundle(bundler.BundleContext{ Context: ctx, Logger: log, ProjectDir: dir, Production: false, + DevMode: !initial, }); err != nil { + if err == bundler.ErrBuildFailed { + log.Error("build failed ...") + return + } errsystem.New(errsystem.ErrInvalidConfiguration, err, errsystem.WithContextMessage(fmt.Sprintf("Failed to bundle project: %s", err))).ShowErrorAndExit() } + ok = true }) - fmt.Println(tui.Text(fmt.Sprintf("✨ Built in %s", time.Since(started).Round(time.Millisecond)))) + if ok { + fmt.Println(tui.Text(fmt.Sprintf("✨ Built in %s", time.Since(started).Round(time.Millisecond)))) + } } // Initial build - build() + build(true) // Watch for changes watcher, err := dev.NewWatcher(log, dir, theproject.Project.Development.Watch.Files, func(path string) { - build() + build(false) isDeliberateRestart = true log.Debug("killing project server") dev.KillProjectServer(projectServerCmd) diff --git a/internal/bundler/bundler.go b/internal/bundler/bundler.go index 19c9dfd0..a0e81b35 100644 --- a/internal/bundler/bundler.go +++ b/internal/bundler/bundler.go @@ -22,6 +22,8 @@ import ( var Version = "dev" +var ErrBuildFailed = fmt.Errorf("build failed") + type AgentConfig struct { ID string `json:"id"` Name string `json:"name"` @@ -35,6 +37,7 @@ type BundleContext struct { Production bool Install bool CI bool + DevMode bool } func bundleJavascript(ctx BundleContext, dir string, outdir string, theproject *project.Project) error { @@ -157,6 +160,10 @@ func bundleJavascript(ctx BundleContext, dir string, outdir string, theproject * fmt.Println(formattedError) } + if ctx.DevMode { + return ErrBuildFailed + } + os.Exit(2) return nil // This line will never be reached due to os.Exit }