diff --git a/cmd/aibmigration/activity.go b/cmd/aibmigration/activity.go index bc0d8fc..ebb839c 100644 --- a/cmd/aibmigration/activity.go +++ b/cmd/aibmigration/activity.go @@ -66,19 +66,16 @@ func (activity *aibActivity) asNewFormatActivity() (a *activities.Activity) { func populateVideoMetadata(ctx context.Context, a *activities.Activity, vidURL string) (err error) { var u *url.URL u, err = url.Parse(vidURL) - if err != nil { return } var meta *videos.VideoInfo meta, err = videos.GetVideoInfo(ctx, u, videos.Options{}) - if err != nil { return } a.Meta = meta - return } diff --git a/cmd/botsu/config.go b/cmd/botsu/config.go index 32dc91c..6309c73 100644 --- a/cmd/botsu/config.go +++ b/cmd/botsu/config.go @@ -73,7 +73,6 @@ func (c *Config) LoadEnv() error { if ok { token, err := os.ReadFile(tokenFile) - if err != nil { return err } @@ -82,22 +81,18 @@ func (c *Config) LoadEnv() error { } token, ok := os.LookupEnv("BOTSU_TOKEN") - if ok { c.Token = token } host, ok := os.LookupEnv("POSTGRES_HOST") - if ok { c.Database.Host = host } port, ok := os.LookupEnv("POSTGRES_PORT") - if ok { portInt, err := strconv.Atoi(port) - if err != nil { return err } @@ -106,10 +101,8 @@ func (c *Config) LoadEnv() error { } userFile, ok := os.LookupEnv("POSTGRES_USER_FILE") - if ok { user, err := os.ReadFile(userFile) - if err != nil { return err } @@ -118,10 +111,8 @@ func (c *Config) LoadEnv() error { } passwordFile, ok := os.LookupEnv("POSTGRES_PASSWORD_FILE") - if ok { password, err := os.ReadFile(passwordFile) - if err != nil { return err } @@ -130,22 +121,18 @@ func (c *Config) LoadEnv() error { } database, ok := os.LookupEnv("POSTGRES_DB") - if ok { c.Database.Database = database } sslMode, ok := os.LookupEnv("POSTGRES_SSL_MODE") - if ok { c.Database.SSLMode = sslMode } connectionString, ok := os.LookupEnv("BOTSU_CONNECTION_STRING") - if ok { connectionURL, err := url.Parse(connectionString) - if err != nil { return err } @@ -154,13 +141,11 @@ func (c *Config) LoadEnv() error { } useMembersIntent, ok := os.LookupEnv("BOTSU_USE_MEMBERS_INTENT") - if ok { c.UseMembersIntent = stringToTruthy(useMembersIntent) } logLevel, ok := os.LookupEnv("BOTSU_LOG_LEVEL") - if ok { if err := c.LogLevel.UnmarshalText([]byte(logLevel)); err != nil { return err @@ -168,16 +153,13 @@ func (c *Config) LoadEnv() error { } noPanic, ok := os.LookupEnv("BOTSU_NO_PANIC") - if ok { c.NoPanic = stringToTruthy(noPanic) } dataUpdateInterval, ok := os.LookupEnv("BOTSU_DATA_UPDATE_INTERVAL") - if ok { duration, err := time.ParseDuration(dataUpdateInterval) - if err != nil { return err } diff --git a/cmd/botsu/main.go b/cmd/botsu/main.go index 56f8504..773cadd 100644 --- a/cmd/botsu/main.go +++ b/cmd/botsu/main.go @@ -145,14 +145,12 @@ func main() { } migrationSource, err := iofs.New(migrations.MigrationFS, ".") - if err != nil { logger.Error("Unable to create migration source", slog.String("err", err.Error())) os.Exit(1) } m, err := migrate.NewWithSourceInstance("migrations.MigrationFS", migrationSource, migrationURL.String()) - if err != nil { logger.Error("Unable to create migration", slog.String("err", err.Error())) os.Exit(1) @@ -160,14 +158,12 @@ func main() { err = m.Up() noChange := errors.Is(err, migrate.ErrNoChange) - if err != nil && !noChange { logger.Error("Unable to run migrations", slog.String("err", err.Error())) os.Exit(1) } ver, dirty, err := m.Version() - if err != nil { logger.Warn("Failed to get database version") } @@ -186,7 +182,6 @@ func main() { } pool, err := pgxpool.New(context.Background(), config.Database.ConnectionString()) - if err != nil { logger.Error("Unable to connect to database", slog.String("err", err.Error())) os.Exit(1) diff --git a/internal/activities/repository.go b/internal/activities/repository.go index 9643692..ac9245f 100755 --- a/internal/activities/repository.go +++ b/internal/activities/repository.go @@ -231,7 +231,6 @@ func (r *ActivityRepository) GetTotalByUserIDGroupByVideoChannel( LIMIT $4 ` rows, err := r.pool.Query(ctx, query, userID, start, end, limit) - if err != nil { return nil, err } @@ -299,7 +298,6 @@ func (r *ActivityRepository) GetTotalByUserIDGroupedByMonth( ` rows, err := r.pool.Query(ctx, query, userID, guildID, start, end) - if err != nil { return nil, err } @@ -356,7 +354,6 @@ func (r *ActivityRepository) GetTotalByUserIDGroupedByDay( ` rows, err := r.pool.Query(ctx, query, userID, guildID, start, end) - if err != nil { return nil, err } @@ -459,7 +456,6 @@ func (r *ActivityRepository) GetByID(ctx context.Context, id uint64, guildID str &activity.ImportedAt, &activity.Meta, ) - if err != nil { return nil, err } diff --git a/internal/bot/bot.go b/internal/bot/bot.go index cf92cbd..cc6fda3 100644 --- a/internal/bot/bot.go +++ b/internal/bot/bot.go @@ -77,7 +77,6 @@ func (b *Bot) onInteractionCreate(s *discordgo.Session, i *discordgo.Interaction stack := debug.Stack() ctx.Logger.Error("Panic occurred", slog.Any("panic", r), slog.Any("stack", string(stack))) _, err := ctx.RespondOrFollowup(unexpectedErrorMessage, false) - if err != nil { ctx.Logger.Error("Failed to send error message", slog.String("err", err.Error())) } @@ -94,7 +93,6 @@ func (b *Bot) onInteractionCreate(s *discordgo.Session, i *discordgo.Interaction if ctx.IsCommand() { _, err = ctx.RespondOrFollowup(unexpectedErrorMessage, false) - if err != nil { ctx.Logger.Error("Failed to send error message", slog.String("err", err.Error())) } @@ -182,9 +180,7 @@ func (b *Bot) Close() { if b.destroyOnClose { b.logger.Debug("Destroying commands") - _, err := b.session.ApplicationCommandBulkOverwrite(b.session.State.User.ID, "", []*discordgo.ApplicationCommand{}) - if err != nil { b.logger.Error("Failed to destroy commands", slog.String("err", err.Error())) } diff --git a/internal/bot/commands/chart.go b/internal/bot/commands/chart.go index 82363ca..63e085f 100644 --- a/internal/bot/commands/chart.go +++ b/internal/bot/commands/chart.go @@ -250,7 +250,6 @@ func (c *ChartCommand) handleYoutubeChannel(ctx *bot.InteractionContext, user *u } resp, err := http.DefaultClient.Do(&req) - if err != nil { return err } @@ -313,11 +312,9 @@ func (c *ChartCommand) Handle(ctx *bot.InteractionContext) error { timezone = *user.Timezone } else if guildID != "" { guild, err := c.gr.FindByID(ctx.ResponseContext(), guildID) - if err != nil && !errors.Is(err, pgx.ErrNoRows) { return err } - if guild != nil && guild.Timezone != nil { timezone = *guild.Timezone } @@ -422,7 +419,6 @@ func (c *ChartCommand) Handle(ctx *bot.InteractionContext) error { } reqBody, err := getQuickChartBarBody(dailyDurations.Keys(), values, goal) - if err != nil { return err } @@ -437,7 +433,6 @@ func (c *ChartCommand) Handle(ctx *bot.InteractionContext) error { } resp, err := http.DefaultClient.Do(&req) - if err != nil { return err } diff --git a/internal/bot/commands/config.go b/internal/bot/commands/config.go index 19ba189..50467fc 100644 --- a/internal/bot/commands/config.go +++ b/internal/bot/commands/config.go @@ -91,7 +91,6 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error { switch options[0].Name { case "timezone": timezone, err := discordutil.GetRequiredStringOption(options, "timezone") - if err != nil { return err } @@ -106,7 +105,6 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error { } err = c.userRepository.SetUserTimezone(ctx.Context(), discordutil.GetInteractionUser(i).ID, timezone) - if err != nil { return err } @@ -114,7 +112,6 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error { embedBuilder.SetDescription("Your timezone has been updated.") case "vn-speed": vnSpeed, err := discordutil.GetRequiredFloatOption(options, "vn-speed") - if err != nil { return err } @@ -127,13 +124,11 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error { embedBuilder.SetDescription("Your visual novel reading speed has been updated.") case "book-speed": bookSpeed, err := discordutil.GetRequiredFloatOption(options, "book-speed") - if err != nil { return err } err = c.userRepository.SetBookReadingSpeed(ctx.Context(), discordutil.GetInteractionUser(i).ID, float32(bookSpeed)) - if err != nil { return err } @@ -141,13 +136,11 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error { embedBuilder.SetDescription("Your book reading speed has been updated.") case "manga-speed": mangaSpeed, err := discordutil.GetRequiredFloatOption(options, "manga-speed") - if err != nil { return err } err = c.userRepository.SetMangaReadingSpeed(ctx.Context(), discordutil.GetInteractionUser(i).ID, float32(mangaSpeed)) - if err != nil { return err } @@ -155,13 +148,11 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error { embedBuilder.SetDescription("Your manga reading speed has been updated.") case "daily-goal": dailyGoal, err := discordutil.GetRequiredUintOption(options, "daily-goal") - if err != nil { return err } err = c.userRepository.SetDailyGoal(ctx.Context(), discordutil.GetInteractionUser(i).ID, int(dailyGoal)) - if err != nil { return err } diff --git a/internal/bot/commands/export.go b/internal/bot/commands/export.go index 70f8f33..ed16e65 100644 --- a/internal/bot/commands/export.go +++ b/internal/bot/commands/export.go @@ -62,7 +62,6 @@ func (c *ExportCommand) Handle(ctx *bot.InteractionContext) error { for _, activity := range activities { err = jsonEncoder.Encode(activity) - if err != nil { return err } diff --git a/internal/bot/commands/goals.go b/internal/bot/commands/goals.go index 608aab3..5652a56 100644 --- a/internal/bot/commands/goals.go +++ b/internal/bot/commands/goals.go @@ -197,7 +197,6 @@ func (c *GoalCommand) handleDelete(cmd *bot.InteractionContext, subcommand *disc func (c *GoalCommand) handleList(cmd *bot.InteractionContext, _ *discordgo.ApplicationCommandInteractionDataOption) error { goals, err := c.goals.CheckAll(cmd.ResponseContext(), cmd.User().ID) - if err != nil { return fmt.Errorf("failed to find goals: %w", err) } @@ -222,7 +221,6 @@ func (c *GoalCommand) handleList(cmd *bot.InteractionContext, _ *discordgo.Appli for _, goal := range goals { nextDueDate, err := c.goals.NextCron(cmd.Context(), goal) - if err != nil { return fmt.Errorf("failed to calculate next due date: %w", err) } diff --git a/internal/bot/commands/guild_config.go b/internal/bot/commands/guild_config.go index 8363415..3a1b59b 100644 --- a/internal/bot/commands/guild_config.go +++ b/internal/bot/commands/guild_config.go @@ -52,7 +52,6 @@ func (c *GuildConfigCommand) Handle(ctx *bot.InteractionContext) error { switch options[0].Name { case "timezone": timezone, err := discordutil.GetRequiredStringOption(options, "timezone") - if err != nil { return err } diff --git a/internal/bot/commands/history.go b/internal/bot/commands/history.go index aaa31d9..0208a8b 100644 --- a/internal/bot/commands/history.go +++ b/internal/bot/commands/history.go @@ -75,7 +75,6 @@ func (c *HistoryCommand) Handle(ctx *bot.InteractionContext) error { } page, err := c.r.PageByUserID(ctx.Context(), user.ID, ctx.Interaction().GuildID, pageSize, offset) - if err != nil { return err } @@ -222,7 +221,6 @@ func (c *HistoryCommand) Handle(ctx *bot.InteractionContext) error { } page, err = c.r.PageByUserID(ciContext, user.ID, ctx.Interaction().GuildID, pageSize, offset) - if err != nil { cancel() return err diff --git a/internal/bot/commands/import.go b/internal/bot/commands/import.go index 5acf11d..c71b27e 100755 --- a/internal/bot/commands/import.go +++ b/internal/bot/commands/import.go @@ -69,7 +69,6 @@ func (c *ImportCommand) handleList( cmd *bot.InteractionContext, ) error { history, err := c.r.GetRecentImportsByUserID(ctx, cmd.User().ID, 10) - if err != nil { return err } diff --git a/internal/bot/commands/leaderboard.go b/internal/bot/commands/leaderboard.go index 72ccd50..50811e5 100644 --- a/internal/bot/commands/leaderboard.go +++ b/internal/bot/commands/leaderboard.go @@ -132,7 +132,6 @@ func (c *LeaderboardCommand) Handle(ctx *bot.InteractionContext) error { timezone = *user.Timezone } else if guildID != "" { guild, err := c.g.FindByID(ctx.ResponseContext(), guildID) - if err != nil && !errors.Is(err, pgx.ErrNoRows) { return err } @@ -184,7 +183,6 @@ func (c *LeaderboardCommand) Handle(ctx *bot.InteractionContext) error { // Note: Do not go over 100 members as Discord will not allow fetching 100+ in a single chunk topMembers, err := c.r.GetTopMembers(ctx.Context(), i.GuildID, 10, start, end) - if err != nil { return err } @@ -194,14 +192,12 @@ func (c *LeaderboardCommand) Handle(ctx *bot.InteractionContext) error { for _, m := range topMembers { guild, err := s.State.Guild(i.GuildID) - if err != nil { missingMembers = append(missingMembers, m.UserID) continue } member, err := s.State.Member(guild.ID, m.UserID) - if err != nil { missingMembers = append(missingMembers, m.UserID) continue @@ -212,7 +208,6 @@ func (c *LeaderboardCommand) Handle(ctx *bot.InteractionContext) error { if len(missingMembers) > 0 { nonce, err := discordutil.NewNonce() - if err != nil { return err } @@ -228,7 +223,6 @@ func (c *LeaderboardCommand) Handle(ctx *bot.InteractionContext) error { defer removeHandler() err = s.RequestGuildMembersList(i.GuildID, missingMembers, 0, nonce, false) - if err != nil { return err } diff --git a/internal/bot/commands/log.go b/internal/bot/commands/log.go index b9df875..f1ed698 100755 --- a/internal/bot/commands/log.go +++ b/internal/bot/commands/log.go @@ -700,7 +700,6 @@ func (c *LogCommand) handleVisualNovel(ctx *bot.InteractionContext, subcommand * if v.ImageNSFW && thumbnail != "" { blurredThumbnail, err := blurImageFromURL(ctx.Context(), thumbnail, 30) - if err != nil { return err } @@ -1021,7 +1020,6 @@ func (c *LogCommand) createAutocompleteResult(ctx context.Context, mediaType, in if mediaType == activities.ActivityMediaTypeAnime { results, err := c.mediaSearcher.SearchAnime(ctx, input, 25) - if err != nil { return nil, err } @@ -1052,7 +1050,6 @@ func (c *LogCommand) createAutocompleteResult(ctx context.Context, mediaType, in } } else if mediaType == activities.ActivityMediaTypeVisualNovel { results, err := c.mediaSearcher.SearchVisualNovel(ctx, input, 25) - if err != nil { return nil, err } @@ -1098,7 +1095,6 @@ func (c *LogCommand) resolveAnimeFromAutocomplete(input string) (*mediadata.Anim id, field := parts[0], parts[1] anime, err := c.mediaSearcher.ReadAnime(context.TODO(), id) - if err != nil { return nil, "", err } @@ -1122,7 +1118,6 @@ func (c *LogCommand) resolveVNFromAutocomplete(input string) (*mediadata.VisualN id, field := parts[0], parts[1] vn, err := c.mediaSearcher.ReadVisualNovel(context.TODO(), id) - if err != nil { return nil, "", err } @@ -1246,27 +1241,22 @@ func isAutocompletedEntry(input string) bool { func blurImageFromURL(ctx context.Context, url string, radius uint32) (imgFile io.Reader, err error) { req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) - if err != nil { return } resp, err := http.DefaultClient.Do(req) - if err != nil { return } - defer resp.Body.Close() srcImage, _, err := image.Decode(resp.Body) - if err != nil { return } img, err := stackblur.Process(srcImage, radius) - if err != nil { return } diff --git a/internal/bot/commands/undo.go b/internal/bot/commands/undo.go index d976ac6..bbf9091 100644 --- a/internal/bot/commands/undo.go +++ b/internal/bot/commands/undo.go @@ -103,13 +103,11 @@ func (c *UndoCommand) undoActivity(ctx *bot.InteractionContext, id uint64) error Components: []discordgo.MessageComponent{row}, Flags: discordgo.MessageFlagsEphemeral, }) - if err != nil { return err } msg, err := ctx.Session().InteractionResponse(ctx.Interaction().Interaction) - if err != nil { return err } @@ -140,7 +138,6 @@ func (c *UndoCommand) undoActivity(ctx *bot.InteractionContext, id uint64) error if ci.MessageComponentData().CustomID == "undo_confirm" { err = c.r.DeleteByID(ciCtx, activity.ID) - if err != nil { return err } diff --git a/internal/goals/goal_service.go b/internal/goals/goal_service.go index c7fb658..f0ed5ca 100644 --- a/internal/goals/goal_service.go +++ b/internal/goals/goal_service.go @@ -19,22 +19,18 @@ func NewGoalService(repo *GoalRepository, ts *users.UserTimeService) *GoalServic func (s *GoalService) NextCron(ctx context.Context, g *Goal) (t time.Time, err error) { location, err := s.ts.GetTimeLocation(ctx, g.UserID, "") - if err != nil { return } - now := time.Now().In(location) return g.NextDueTime(now) } func (s *GoalService) PreviousCron(ctx context.Context, g *Goal) (t time.Time, err error) { location, err := s.ts.GetTimeLocation(ctx, g.UserID, "") - if err != nil { return } - now := time.Now().In(location) return g.PreviousDueTime(now) } diff --git a/internal/goals/repository.go b/internal/goals/repository.go index 12c9afd..cc22057 100644 --- a/internal/goals/repository.go +++ b/internal/goals/repository.go @@ -71,11 +71,9 @@ func (r *GoalRepository) FindByUserID(ctx context.Context, userID string) (goals AND user_id = $1`, userID, ) - if err != nil { return } - defer rows.Close() for rows.Next() { @@ -93,7 +91,6 @@ func (r *GoalRepository) FindByUserID(ctx context.Context, userID string) (goals &g.DueAt, &g.CreatedAt, ) - if err != nil { return } @@ -106,7 +103,6 @@ func (r *GoalRepository) FindByUserID(ctx context.Context, userID string) (goals func (r *GoalRepository) BeginUpdateTxByUserID(ctx context.Context, userID string) (goals []*Goal, tx pgx.Tx, err error) { tx, err = r.pool.Begin(ctx) - if err != nil { return } @@ -120,7 +116,6 @@ func (r *GoalRepository) BeginUpdateTxByUserID(ctx context.Context, userID strin FOR UPDATE`, userID, ) - if err != nil { return } diff --git a/internal/guilds/repository.go b/internal/guilds/repository.go index 7a1c31e..93af494 100644 --- a/internal/guilds/repository.go +++ b/internal/guilds/repository.go @@ -65,12 +65,10 @@ func (r *GuildRepository) FindOrCreate(ctx context.Context, id string) (*Guild, } guild, err := r.FindByID(ctx, id) - if err != nil { if errors.Is(err, pgx.ErrNoRows) { guild = NewGuild(id) err = r.Create(ctx, guild) - if err != nil { return nil, err } diff --git a/internal/mediadata/anime.go b/internal/mediadata/anime.go index a20be32..cc6010b 100644 --- a/internal/mediadata/anime.go +++ b/internal/mediadata/anime.go @@ -88,7 +88,6 @@ func (a *Anime) SearchFields() []string { func DownloadAnime(ctx context.Context) (anime []Anime, err error) { aodbData, err := otame.DownloadAODB(ctx) - if err != nil { err = fmt.Errorf("unable to download anime data offline datavase: %w", err) return @@ -116,7 +115,6 @@ func DownloadAnime(ctx context.Context) (anime []Anime, err error) { for _, src := range aodbEntry.Sources { srcURL, err := url.Parse(src) - if err != nil { err = fmt.Errorf("unable to parse source URL: %w", err) return nil, err @@ -141,7 +139,6 @@ func DownloadAnime(ctx context.Context) (anime []Anime, err error) { } anidbData, err := otame.DownloadAniDB(ctx) - if err != nil { err = fmt.Errorf("unable to download AniDB: %w", err) return diff --git a/internal/mediadata/searcher.go b/internal/mediadata/searcher.go index b24bab4..0a0b9b1 100644 --- a/internal/mediadata/searcher.go +++ b/internal/mediadata/searcher.go @@ -40,13 +40,11 @@ func (rw *batchedReadWriter[T, PT]) read(ctx context.Context, id string) (record req := bluge.NewTermQuery(id).SetField("_id") dmi, err := rw.r.Search(ctx, bluge.NewTopNSearch(1, req)) - if err != nil { return } next, err := dmi.Next() - if err != nil { return } @@ -63,11 +61,9 @@ func (rw *batchedReadWriter[T, PT]) read(ctx context.Context, id string) (record fields[field] = string(value) return true }) - if err != nil { return } - err = record.Unmarshal(fields) return } @@ -83,7 +79,6 @@ func (rw *batchedReadWriter[T, PT]) search(ctx context.Context, matchQuery strin query := bluge.NewMatchQuery(matchQuery).SetField(field) searchRequest := bluge.NewTopNSearch(limit, query) dmi, err := rw.r.Search(ctx, searchRequest) - if err != nil { return nil, err } @@ -98,7 +93,6 @@ func (rw *batchedReadWriter[T, PT]) search(ctx context.Context, matchQuery strin fields[field] = string(value) return true }) - if err != nil { break } @@ -127,7 +121,6 @@ func (rw *batchedReadWriter[T, PT]) overwriteData(data []T) (err error) { defer rw.mu.Unlock() w, err := bluge.OpenWriter(rw.config) - if err != nil { return } @@ -137,7 +130,6 @@ func (rw *batchedReadWriter[T, PT]) overwriteData(data []T) (err error) { var doc *bluge.Document for _, record := range data { doc, err = record.Marshal() - if err != nil { return } @@ -208,7 +200,6 @@ func (s *MediaSearcher) UpdateData(ctx context.Context) (err error) { go func() { s.Logger.Info("Downloaded anime data") animeData, err := DownloadAnime(ctx) - if err != nil { errs <- fmt.Errorf("unable to download anime data: %w", err) return @@ -225,7 +216,6 @@ func (s *MediaSearcher) UpdateData(ctx context.Context) (err error) { go func() { s.Logger.Info("Downloaded visual novel data") vnData, err := DownloadVisualNovels(ctx) - if err != nil { errs <- fmt.Errorf("unable to download visual novel data: %w", err) return diff --git a/internal/mediadata/visual_novel.go b/internal/mediadata/visual_novel.go index f4b6e0c..7f07807 100644 --- a/internal/mediadata/visual_novel.go +++ b/internal/mediadata/visual_novel.go @@ -77,7 +77,6 @@ func (vn *VisualNovel) SearchFields() []string { func DownloadVisualNovels(ctx context.Context) (vns []VisualNovel, err error) { vndbDataFS, err := otame.DownloadVNDB(ctx) - if err != nil { err = fmt.Errorf("unable to download VNDB data: %w", err) return @@ -94,7 +93,6 @@ func DownloadVisualNovels(ctx context.Context) (vns []VisualNovel, err error) { }() vnData, err := vndbDataFS.Open("db/vn") - if err != nil { err = fmt.Errorf("unable to open VNDB data: %w", err) return @@ -108,7 +106,6 @@ func DownloadVisualNovels(ctx context.Context) (vns []VisualNovel, err error) { for { var vn otame.VNDBVisualNovel vn, err = vndbIter.Next() - if err != nil { if err == otame.ErrFinished { err = nil @@ -133,21 +130,17 @@ func DownloadVisualNovels(ctx context.Context) (vns []VisualNovel, err error) { } vnTitleData, err := vndbDataFS.Open("db/vn_titles") - if err != nil { err = fmt.Errorf("unable to open VNDB title data: %w", err) return } - defer vnTitleData.Close() vnTitleIter := otame.NewVNDBTitleDecoder(vnTitleData) for { var vnTitle otame.VNDBTitle - vnTitle, err = vnTitleIter.Next() - if err != nil { if err == otame.ErrFinished { err = nil @@ -179,21 +172,16 @@ func DownloadVisualNovels(ctx context.Context) (vns []VisualNovel, err error) { } vnImageData, err := vndbDataFS.Open("db/images") - if err != nil { err = fmt.Errorf("unable to open VNDB image data: %w", err) return } - defer vnImageData.Close() vnImageIter := otame.NewVNDBImageDecoder(vnImageData) - for { var vnImage otame.VNDBImage - vnImage, err = vnImageIter.Next() - if err != nil { if err == otame.ErrFinished { err = nil @@ -211,7 +199,6 @@ func DownloadVisualNovels(ctx context.Context) (vns []VisualNovel, err error) { } vns = make([]VisualNovel, 0, len(vnMap)) - for _, vn := range vnMap { vns = append(vns, vn) } diff --git a/internal/users/time_service.go b/internal/users/time_service.go index c738ae0..1bda3b0 100644 --- a/internal/users/time_service.go +++ b/internal/users/time_service.go @@ -37,21 +37,17 @@ func (s *UserTimeService) GetTimezone(ctx context.Context, userID, guildID strin func (s *UserTimeService) GetTimeLocation(ctx context.Context, userID, guildID string) (*time.Location, error) { timezone, err := s.GetTimezone(ctx, userID, guildID) - if err != nil { return nil, err } - return time.LoadLocation(timezone) } func (s *UserTimeService) GetTime(ctx context.Context, userID, guildID string) (time.Time, error) { location, err := s.GetTimeLocation(ctx, userID, guildID) - if err != nil { return time.Time{}, err } - return time.Now().In(location), nil } diff --git a/internal/videos/ytchannel/ytchannel.go b/internal/videos/ytchannel/ytchannel.go index 603ac12..d9a3e5d 100644 --- a/internal/videos/ytchannel/ytchannel.go +++ b/internal/videos/ytchannel/ytchannel.go @@ -80,21 +80,17 @@ func GetYoutubeChannel(ctx context.Context, handleOrID string) (ch *Channel, err } req, err := http.NewRequestWithContext(ctx, http.MethodGet, profileURL, nil) - if err != nil { return } resp, err := HTTPClient.Do(req) - if err != nil { return } - defer resp.Body.Close() body, err := io.ReadAll(resp.Body) - if err != nil { return } diff --git a/pkg/discordutil/nonce.go b/pkg/discordutil/nonce.go index 48a64e0..d054ba4 100644 --- a/pkg/discordutil/nonce.go +++ b/pkg/discordutil/nonce.go @@ -23,16 +23,12 @@ func NewNonce() (nonce string, err error) { randomBytes := make([]byte, 8) nonceBytes := make([]byte, 16) - _, err = rand.Read(randomBytes) - - if err != nil { + if _, err = rand.Read(randomBytes); err != nil { return } - copy(nonceBytes, randomBytes) binary.BigEndian.PutUint64(nonceBytes[8:], uint64(timestamp)) nonce = hex.EncodeToString(nonceBytes) - return } diff --git a/pkg/otame/anidb.go b/pkg/otame/anidb.go index 7443141..c6339dc 100644 --- a/pkg/otame/anidb.go +++ b/pkg/otame/anidb.go @@ -68,7 +68,6 @@ func (a *AniDBEntryDecoder) Next() (entry AniDBEntry, err error) { var line []string line, err = a.readLine() - if err != nil { return } diff --git a/pkg/otame/aodb.go b/pkg/otame/aodb.go index 5ac6a22..e016557 100644 --- a/pkg/otame/aodb.go +++ b/pkg/otame/aodb.go @@ -89,7 +89,6 @@ func (a *AnimeOfflineDatabaseDecoder) locateDataArray() error { // expect a '[' t, err := a.decoder.Token() - if err != nil { return err } @@ -99,6 +98,5 @@ func (a *AnimeOfflineDatabaseDecoder) locateDataArray() error { } a.caughtUp = true - return nil } diff --git a/pkg/otame/download.go b/pkg/otame/download.go index dbb5489..f387694 100644 --- a/pkg/otame/download.go +++ b/pkg/otame/download.go @@ -51,19 +51,16 @@ type fsCloser struct { // file. The caller is responsible for closing the ReadCloser. func DownloadAODB(ctx context.Context) (r io.ReadCloser, err error) { req, err := http.NewRequestWithContext(ctx, http.MethodGet, aodbDownloadURL, nil) - if err != nil { return } resp, err := http.DefaultClient.Do(req) - if err != nil { return } r = resp.Body - return } @@ -83,19 +80,16 @@ func DownloadAniDB(ctx context.Context) (r io.ReadCloser, err error) { } req.Header.Set("User-Agent", userAgent) - if err != nil { return } resp, err := http.DefaultClient.Do(req) - if err != nil { return } r, err = gzip.NewReader(resp.Body) - if err != nil { resp.Body.Close() return @@ -105,7 +99,6 @@ func DownloadAniDB(ctx context.Context) (r io.ReadCloser, err error) { ReadCloser: r, inner: resp.Body, } - return } @@ -121,29 +114,23 @@ func DownloadVNDB(ctx context.Context) (*fsCloser, error) { // will remove the temporary directory. func DownloadVNDBUsingTempDir(ctx context.Context, temp string) (fsc *fsCloser, err error) { req, err := http.NewRequestWithContext(ctx, http.MethodGet, vndbDownloadURL, nil) - if err != nil { return } resp, err := http.DefaultClient.Do(req) - if err != nil { return } - defer resp.Body.Close() r, err := zstd.NewReader(resp.Body) - if err != nil { return } - defer r.Close() tempDir, err := os.MkdirTemp(temp, "vndb") - if err != nil { return } @@ -157,7 +144,6 @@ func DownloadVNDBUsingTempDir(ctx context.Context, temp string) (fsc *fsCloser, var header *tar.Header header, err = tarReader.Next() - if err != nil { if err == io.EOF { err = nil @@ -173,13 +159,11 @@ func DownloadVNDBUsingTempDir(ctx context.Context, temp string) (fsc *fsCloser, var file *os.File file, err = os.Create(path.Join(tempDir, header.Name)) - if err != nil { break } _, err = io.Copy(file, tarReader) - if err != nil { file.Close() break @@ -200,6 +184,5 @@ func DownloadVNDBUsingTempDir(ctx context.Context, temp string) (fsc *fsCloser, FS: os.DirFS(tempDir), Close: func() error { return os.RemoveAll(tempDir) }, } - return } diff --git a/pkg/otame/vndb.go b/pkg/otame/vndb.go index 0de331e..7e696f6 100644 --- a/pkg/otame/vndb.go +++ b/pkg/otame/vndb.go @@ -167,13 +167,11 @@ func (d *genericLineDecoder[T]) Next() (entry T, err error) { var line []string line, err = d.readLine() - if err != nil { return } entry, err = d.unmarshal(line) - if err != nil { err = fmt.Errorf("line %d: %w", d.line, err) }