Return errors to main

This commit is contained in:
Ryan Cavicchioni 2022-09-09 10:21:07 -05:00
parent 211f963b87
commit 6bd4744745
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 7 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package bot package bot
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -84,12 +85,12 @@ func Run() error {
} }
if C.DiscordToken == "" { if C.DiscordToken == "" {
log.Fatalf("Discord token is not set") return errors.New("discord token not set")
} }
dg, err := discordgo.New(fmt.Sprintf("Bot %s", C.DiscordToken)) dg, err := discordgo.New(fmt.Sprintf("Bot %s", C.DiscordToken))
if err != nil { if err != nil {
log.Fatalf("error creating Discord session: %v\n", err) return fmt.Errorf("error creating discord session: %v", err)
} }
b := NewBot(dg, C) b := NewBot(dg, C)
@ -99,7 +100,7 @@ func Run() error {
dg.Identify.Intents = discordgo.IntentsGuildMessages | discordgo.IntentsDirectMessages dg.Identify.Intents = discordgo.IntentsGuildMessages | discordgo.IntentsDirectMessages
if err = dg.Open(); err != nil { if err = dg.Open(); err != nil {
log.Fatalf("error opening connection: %v\n", err) return fmt.Errorf("error opening connection: %v", err)
} }
log.Info("The bot is now running. Press CTRL-C to exit.") log.Info("The bot is now running. Press CTRL-C to exit.")

View File

@ -1,13 +1,13 @@
package main package main
import ( import (
"os"
"git.kill0.net/chill9/beepboop/bot" "git.kill0.net/chill9/beepboop/bot"
log "github.com/sirupsen/logrus"
) )
func main() { func main() {
if err := bot.Run(); err != nil { if err := bot.Run(); err != nil {
os.Exit(1) log.Fatal(err)
} }
} }