Skip to content

Commit

Permalink
fix: bubbles up unclean error exits (#170)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

#169

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
  • Loading branch information
AlexsJones authored Sep 23, 2022
1 parent b655e88 commit 9f7db02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ var startCmd = &cobra.Command{
})
if err != nil {
log.Error(err)
os.Exit(1)
}

rt.Start()
if err := rt.Start(); err != nil {
log.Error(err)
os.Exit(1)
}
},
}
15 changes: 7 additions & 8 deletions pkg/runtime/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ package runtime

import (
"context"
"errors"
"os"
"os/signal"
"syscall"

"golang.org/x/sync/errgroup"
)

func (r *Runtime) Start() {
func (r *Runtime) Start() error {
if r.Service == nil {
r.Logger.Error("no Service set")
return
return errors.New("no Service set")
}
if len(r.SyncImpl) == 0 {
r.Logger.Error("no SyncImplementation set")
return
return errors.New("no SyncImplementation set")
}
if r.Evaluator == nil {
r.Logger.Error("no Evaluator set")
return
return errors.New("no Evaluator set")
}

ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
Expand All @@ -40,6 +38,7 @@ func (r *Runtime) Start() {

<-gCtx.Done()
if err := g.Wait(); err != nil {
r.Logger.Error(err)
return err
}
return nil
}

0 comments on commit 9f7db02

Please sign in to comment.