Skip to content

Commit

Permalink
Merge pull request #570 from cybertec-postgresql/569-unhide-panics
Browse files Browse the repository at this point in the history
[-] make sure panics output won't be hidden, fixes #569
  • Loading branch information
pashagolub authored May 24, 2023
2 parents 66372b6 + 23590cb commit 529506d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"runtime/debug"
"syscall"

"github.com/cybertec-postgresql/pg_timetable/internal/api"
Expand Down Expand Up @@ -43,6 +44,7 @@ const (
ExitCodeUpgradeError
ExitCodeUserCancel
ExitCodeShutdownCommand
ExitCodeFatalError
)

var exitCode = ExitCodeOK
Expand All @@ -65,12 +67,6 @@ func printVersion() {
}

func main() {
defer func() { os.Exit(exitCode) }()

ctx, cancel := context.WithCancel(context.Background())
SetupCloseHandler(cancel)
defer cancel()

cmdOpts, err := config.NewConfig(os.Stdout)
if err != nil {
if cmdOpts != nil && cmdOpts.VersionOnly() {
Expand All @@ -81,12 +77,22 @@ func main() {
exitCode = ExitCodeConfigError
return
}

if cmdOpts.Version {
printVersion()
}

logger := log.Init(cmdOpts.Logging)
ctx, cancel := context.WithCancel(context.Background())
SetupCloseHandler(cancel)
defer func() {
cancel()
if err := recover(); err != nil {
exitCode = ExitCodeFatalError
logger.WithField("callstack", string(debug.Stack())).Error(err)
}
os.Exit(exitCode)
}()

apiserver := api.Init(cmdOpts.RESTApi, logger)

if pge, err = pgengine.New(ctx, *cmdOpts, logger); err != nil {
Expand Down

0 comments on commit 529506d

Please sign in to comment.