From 6bd4744745cfac38aebbafda4889f230878d8d89 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Fri, 9 Sep 2022 10:21:07 -0500 Subject: [PATCH] Return errors to main --- bot/bot.go | 7 ++++--- cmd/bb/main.go | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bot/bot.go b/bot/bot.go index 2bbbb29..4c7acd6 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -1,6 +1,7 @@ package bot import ( + "errors" "fmt" "os" "os/signal" @@ -84,12 +85,12 @@ func Run() error { } 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)) 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) @@ -99,7 +100,7 @@ func Run() error { dg.Identify.Intents = discordgo.IntentsGuildMessages | discordgo.IntentsDirectMessages 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.") diff --git a/cmd/bb/main.go b/cmd/bb/main.go index 13d2dac..691714b 100644 --- a/cmd/bb/main.go +++ b/cmd/bb/main.go @@ -1,13 +1,13 @@ package main import ( - "os" - "git.kill0.net/chill9/beepboop/bot" + + log "github.com/sirupsen/logrus" ) func main() { if err := bot.Run(); err != nil { - os.Exit(1) + log.Fatal(err) } }