Skip to content

Commit

Permalink
ensure %w is used in calls to errs.Appendf()
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaaaWhatsUpDoc committed Jan 19, 2024
1 parent 0b8d85d commit a363575
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
7 changes: 2 additions & 5 deletions internal/media/refetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ func (m *Manager) RefetchEmojis(ctx context.Context, domain string, dereferenceM
for {
// Fetch next block of emojis from database
emojis, err := m.state.DB.GetEmojisBy(ctx, domain, false, true, "", maxShortcodeDomain, "", 20)
if err != nil {
if !errors.Is(err, db.ErrNoEntries) {
// an actual error has occurred
log.Errorf(ctx, "error fetching emojis from database: %s", err)
}
if err != nil && !errors.Is(err, db.ErrNoEntries) {
log.Errorf(ctx, "error fetching emojis from database: %s", err)
break
}

Expand Down
2 changes: 1 addition & 1 deletion internal/transport/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (t *transport) BatchDeliver(ctx context.Context, b []byte, recipients []*ur
// Attempt to deliver data to recipient.
if err := t.deliver(ctx, b, to); err != nil {
mutex.Lock() // safely append err to accumulator.
errs.Appendf("error delivering to %s: %v", to, err)
errs.Appendf("error delivering to %s: %w", to, err)
mutex.Unlock()
}
}
Expand Down
24 changes: 12 additions & 12 deletions internal/typeutils/internaltofrontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1563,15 +1563,15 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
func (c *Converter) convertAttachmentsToAPIAttachments(ctx context.Context, attachments []*gtsmodel.MediaAttachment, attachmentIDs []string) ([]*apimodel.Attachment, error) {
var errs gtserror.MultiError

if len(attachments) == 0 {
if len(attachments) == 0 && len(attachmentIDs) > 0 {
// GTS model attachments were not populated

var err error

// Fetch GTS models for attachment IDs
attachments, err = c.state.DB.GetAttachmentsByIDs(ctx, attachmentIDs)
if err != nil {
errs.Appendf("error fetching attachments from database: %v", err)
errs.Appendf("error fetching attachments from database: %w", err)
}
}

Expand All @@ -1582,7 +1582,7 @@ func (c *Converter) convertAttachmentsToAPIAttachments(ctx context.Context, atta
for _, attachment := range attachments {
apiAttachment, err := c.AttachmentToAPIAttachment(ctx, attachment)
if err != nil {
errs.Appendf("error converting attchment %s to api attachment: %v", attachment.ID, err)
errs.Appendf("error converting attchment %s to api attachment: %w", attachment.ID, err)
continue
}
apiAttachments = append(apiAttachments, &apiAttachment)
Expand All @@ -1595,15 +1595,15 @@ func (c *Converter) convertAttachmentsToAPIAttachments(ctx context.Context, atta
func (c *Converter) convertEmojisToAPIEmojis(ctx context.Context, emojis []*gtsmodel.Emoji, emojiIDs []string) ([]apimodel.Emoji, error) {
var errs gtserror.MultiError

if len(emojis) == 0 {
if len(emojis) == 0 && len(emojiIDs) > 0 {
// GTS model attachments were not populated

var err error

// Fetch GTS models for emoji IDs
emojis, err = c.state.DB.GetEmojisByIDs(ctx, emojiIDs)
if err != nil {
errs.Appendf("error fetching emojis from database: %v", err)
errs.Appendf("error fetching emojis from database: %w", err)
}
}

Expand All @@ -1614,7 +1614,7 @@ func (c *Converter) convertEmojisToAPIEmojis(ctx context.Context, emojis []*gtsm
for _, emoji := range emojis {
apiEmoji, err := c.EmojiToAPIEmoji(ctx, emoji)
if err != nil {
errs.Appendf("error converting emoji %s to api emoji: %v", emoji.ID, err)
errs.Appendf("error converting emoji %s to api emoji: %w", emoji.ID, err)
continue
}
apiEmojis = append(apiEmojis, apiEmoji)
Expand All @@ -1627,15 +1627,15 @@ func (c *Converter) convertEmojisToAPIEmojis(ctx context.Context, emojis []*gtsm
func (c *Converter) convertMentionsToAPIMentions(ctx context.Context, mentions []*gtsmodel.Mention, mentionIDs []string) ([]apimodel.Mention, error) {
var errs gtserror.MultiError

if len(mentions) == 0 {
if len(mentions) == 0 && len(mentionIDs) > 0 {
var err error

// GTS model mentions were not populated
//
// Fetch GTS models for mention IDs
mentions, err = c.state.DB.GetMentions(ctx, mentionIDs)
if err != nil {
errs.Appendf("error fetching mentions from database: %v", err)
errs.Appendf("error fetching mentions from database: %w", err)
}
}

Expand All @@ -1646,7 +1646,7 @@ func (c *Converter) convertMentionsToAPIMentions(ctx context.Context, mentions [
for _, mention := range mentions {
apiMention, err := c.MentionToAPIMention(ctx, mention)
if err != nil {
errs.Appendf("error converting mention %s to api mention: %v", mention.ID, err)
errs.Appendf("error converting mention %s to api mention: %w", mention.ID, err)
continue
}
apiMentions = append(apiMentions, apiMention)
Expand All @@ -1659,12 +1659,12 @@ func (c *Converter) convertMentionsToAPIMentions(ctx context.Context, mentions [
func (c *Converter) convertTagsToAPITags(ctx context.Context, tags []*gtsmodel.Tag, tagIDs []string) ([]apimodel.Tag, error) {
var errs gtserror.MultiError

if len(tags) == 0 {
if len(tags) == 0 && len(tagIDs) > 0 {
var err error

tags, err = c.state.DB.GetTags(ctx, tagIDs)
if err != nil {
errs.Appendf("error fetching tags from database: %v", err)
errs.Appendf("error fetching tags from database: %w", err)
}
}

Expand All @@ -1675,7 +1675,7 @@ func (c *Converter) convertTagsToAPITags(ctx context.Context, tags []*gtsmodel.T
for _, tag := range tags {
apiTag, err := c.TagToAPITag(ctx, tag, false)
if err != nil {
errs.Appendf("error converting tag %s to api tag: %v", tag.ID, err)
errs.Appendf("error converting tag %s to api tag: %w", tag.ID, err)
continue
}
apiTags = append(apiTags, apiTag)
Expand Down

0 comments on commit a363575

Please sign in to comment.