From 7f91c67d576d2d69eeba32d88104ae3337b84174 Mon Sep 17 00:00:00 2001 From: Jye Cusch Date: Fri, 4 Oct 2024 18:46:26 +1000 Subject: [PATCH 1/5] improve errors printed when services fail --- pkg/project/batch.go | 2 +- pkg/project/project.go | 18 ++++++++++++++---- pkg/project/service.go | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/project/batch.go b/pkg/project/batch.go index 72733c9ea..6e83209e0 100644 --- a/pkg/project/batch.go +++ b/pkg/project/batch.go @@ -107,7 +107,7 @@ func (s *Batch) Run(stop <-chan bool, updates chan<- ServiceRunUpdate, env map[s go func() { err := cmd.Start() if err != nil { - errChan <- err + errChan <- fmt.Errorf("error starting service %s: %w", s.Name, err) } else { updates <- ServiceRunUpdate{ ServiceName: s.Name, diff --git a/pkg/project/project.go b/pkg/project/project.go index f394ba037..ff7e84891 100644 --- a/pkg/project/project.go +++ b/pkg/project/project.go @@ -421,7 +421,7 @@ func (p *Project) RunServicesWithCommand(localCloud *cloud.LocalCloud, stop <-ch group.Go(func() error { port, err := localCloud.AddService(svc.GetFilePath()) if err != nil { - return err + return fmt.Errorf("unable to add service %s: %w", svc.GetFilePath(), err) } envVariables := map[string]string{ @@ -434,7 +434,12 @@ func (p *Project) RunServicesWithCommand(localCloud *cloud.LocalCloud, stop <-ch envVariables[key] = value } - return svc.Run(stopChannels[idx], updates, envVariables) + err = svc.Run(stopChannels[idx], updates, envVariables) + if err != nil { + return fmt.Errorf("%s: %w", svc.GetFilePath(), err) + } + + return nil }) } @@ -456,7 +461,7 @@ func (p *Project) RunBatchesWithCommand(localCloud *cloud.LocalCloud, stop <-cha group.Go(func() error { port, err := localCloud.AddBatch(svc.GetFilePath()) if err != nil { - return err + return fmt.Errorf("unable to add batch %s: %w", svc.GetFilePath(), err) } envVariables := map[string]string{ @@ -469,7 +474,12 @@ func (p *Project) RunBatchesWithCommand(localCloud *cloud.LocalCloud, stop <-cha envVariables[key] = value } - return svc.Run(stopChannels[idx], updates, envVariables) + err = svc.Run(stopChannels[idx], updates, envVariables) + if err != nil { + return fmt.Errorf("%s: %w", svc.GetFilePath(), err) + } + + return nil }) } diff --git a/pkg/project/service.go b/pkg/project/service.go index 0585ed0a3..e83e9e752 100644 --- a/pkg/project/service.go +++ b/pkg/project/service.go @@ -278,7 +278,7 @@ func (s *Service) Run(stop <-chan bool, updates chan<- ServiceRunUpdate, env map go func() { err := cmd.Start() if err != nil { - errChan <- err + errChan <- fmt.Errorf("error starting service %s: %w", s.Name, err) } else { updates <- ServiceRunUpdate{ ServiceName: s.Name, From 474904b6b075ece8e9cc5243657b071609798d6e Mon Sep 17 00:00:00 2001 From: Jye Cusch Date: Fri, 4 Oct 2024 18:47:46 +1000 Subject: [PATCH 2/5] fix(start): stop exit status 1 printing when terminating go services --- pkg/project/batch.go | 12 ++++++++++++ pkg/project/service.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/project/batch.go b/pkg/project/batch.go index 6e83209e0..a14d4a24d 100644 --- a/pkg/project/batch.go +++ b/pkg/project/batch.go @@ -118,6 +118,18 @@ func (s *Batch) Run(stop <-chan bool, updates chan<- ServiceRunUpdate, env map[s } err = cmd.Wait() + if err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + if commandParts[0] == "go" { + // go run often returns 1, even when the program would have exited normally, so we ignore this error + // see: https://github.com/golang/go/issues/13440 + if exitErr.ExitCode() == 1 { + err = nil + } + } + } + } + errChan <- err }() diff --git a/pkg/project/service.go b/pkg/project/service.go index e83e9e752..835f82721 100644 --- a/pkg/project/service.go +++ b/pkg/project/service.go @@ -289,6 +289,18 @@ func (s *Service) Run(stop <-chan bool, updates chan<- ServiceRunUpdate, env map } err = cmd.Wait() + if err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + if commandParts[0] == "go" { + // go run often returns 1, even when the program would have exited normally, so we ignore this error + // see: https://github.com/golang/go/issues/13440 + if exitErr.ExitCode() == 1 { + err = nil + } + } + } + } + errChan <- err }() From 57ec931f456d37c2900ced35ed6fddd0b09f2198 Mon Sep 17 00:00:00 2001 From: Jye Cusch Date: Tue, 8 Oct 2024 10:22:11 +1100 Subject: [PATCH 3/5] ci: remove codecov upload --- .github/workflows/cli-test.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/cli-test.yaml b/.github/workflows/cli-test.yaml index f7879a76d..67512db08 100644 --- a/.github/workflows/cli-test.yaml +++ b/.github/workflows/cli-test.yaml @@ -47,13 +47,6 @@ jobs: run: make build - name: Run Tests run: make test-coverage - - name: Upload Coverage Report - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos - files: all.coverprofile - flags: unittests - fail_ci_if_error: true other-os-build: strategy: matrix: From e39f64db22ac8862ee6bf3fe94abbf2f1c8f7a76 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Tue, 8 Oct 2024 11:58:31 +1100 Subject: [PATCH 4/5] log app level runtime errors rather than treating them as fatal --- pkg/project/batch.go | 17 ++++++++--------- pkg/project/service.go | 16 +++++++--------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/pkg/project/batch.go b/pkg/project/batch.go index a14d4a24d..cd9473675 100644 --- a/pkg/project/batch.go +++ b/pkg/project/batch.go @@ -118,19 +118,18 @@ func (s *Batch) Run(stop <-chan bool, updates chan<- ServiceRunUpdate, env map[s } err = cmd.Wait() + if err != nil { - if exitErr, ok := err.(*exec.ExitError); ok { - if commandParts[0] == "go" { - // go run often returns 1, even when the program would have exited normally, so we ignore this error - // see: https://github.com/golang/go/issues/13440 - if exitErr.ExitCode() == 1 { - err = nil - } - } + // provide runtime errors as a run update rather than as a fatal error + updates <- ServiceRunUpdate{ + ServiceName: s.Name, + Label: "nitric", + Status: ServiceRunStatus_Error, + Err: err, } } - errChan <- err + errChan <- nil }() go func(cmd *exec.Cmd) { diff --git a/pkg/project/service.go b/pkg/project/service.go index 835f82721..04346ea12 100644 --- a/pkg/project/service.go +++ b/pkg/project/service.go @@ -290,18 +290,16 @@ func (s *Service) Run(stop <-chan bool, updates chan<- ServiceRunUpdate, env map err = cmd.Wait() if err != nil { - if exitErr, ok := err.(*exec.ExitError); ok { - if commandParts[0] == "go" { - // go run often returns 1, even when the program would have exited normally, so we ignore this error - // see: https://github.com/golang/go/issues/13440 - if exitErr.ExitCode() == 1 { - err = nil - } - } + // provide runtime errors as a run update rather than as a fatal error + updates <- ServiceRunUpdate{ + ServiceName: s.Name, + Label: "nitric", + Status: ServiceRunStatus_Error, + Err: err, } } - errChan <- err + errChan <- nil }() go func(cmd *exec.Cmd) { From f0f169c49d82f97b3d782ccb978fa355d489fede Mon Sep 17 00:00:00 2001 From: Jye Cusch Date: Mon, 14 Oct 2024 13:27:21 +1100 Subject: [PATCH 5/5] lint --- pkg/project/batch.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/project/batch.go b/pkg/project/batch.go index cd9473675..227f82a93 100644 --- a/pkg/project/batch.go +++ b/pkg/project/batch.go @@ -118,7 +118,6 @@ func (s *Batch) Run(stop <-chan bool, updates chan<- ServiceRunUpdate, env map[s } err = cmd.Wait() - if err != nil { // provide runtime errors as a run update rather than as a fatal error updates <- ServiceRunUpdate{