refactor: add missing defers and handle error returned by bot.Run gracefully
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dawid Wysokiński 2023-01-22 09:29:20 +01:00
parent 23b3da14a5
commit c15cafc1d7
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892

View File

@ -37,6 +37,9 @@ func New() *cli.Command {
if err != nil {
return fmt.Errorf("internal.NewBunDB: %w", err)
}
defer func() {
_ = db.Close()
}()
client, err := internal.NewTWHelpClient(c.App.Version)
if err != nil {
@ -67,7 +70,12 @@ func New() *cli.Command {
}
go func() {
_ = bot.Run()
if runErr := bot.Run(); runErr != nil {
logger.Fatal("bot.Run: " + runErr.Error())
}
}()
defer func() {
_ = bot.Close()
}()
if err = os.WriteFile(healthyFilePath, []byte("healthy"), healthyFilePerm); err != nil {
@ -78,10 +86,6 @@ func New() *cli.Command {
waitForSignal(c.Context)
if err = bot.Close(); err != nil {
return fmt.Errorf("bot.Close: %w", err)
}
return nil
},
}