Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bubbles up unclean error exits #170

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}