Skip to content

Commit

Permalink
[chore] improve errors returned fetching account/statues from DB (#1084)
Browse files Browse the repository at this point in the history
Signed-off-by: kim <grufwub@gmail.com>

Signed-off-by: kim <grufwub@gmail.com>
  • Loading branch information
NyaaaWhatsUpDoc committed Nov 20, 2022
1 parent 5d55e8d commit 2eea3d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion internal/db/bundb/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package bundb
import (
"context"
"errors"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -168,7 +169,7 @@ func (a *accountDB) getAccount(ctx context.Context, lookup string, dbQuery func(
// Set the account's related emojis
account.Emojis, err = a.emojis.emojisFromIDs(ctx, account.EmojiIDs)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting account emojis: %w", err)
}
}

Expand Down
15 changes: 8 additions & 7 deletions internal/db/bundb/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"database/sql"
"errors"
"fmt"
"time"

"codeberg.org/gruf/go-cache/v3/result"
Expand Down Expand Up @@ -120,7 +121,7 @@ func (s *statusDB) getStatus(ctx context.Context, lookup string, dbQuery func(*g

if status.InReplyToID != "" {
// Also load in-reply-to status
status.InReplyTo = &gtsmodel.Status{}
status.InReplyTo = new(gtsmodel.Status)
err := s.conn.NewSelect().Model(status.InReplyTo).
Where("? = ?", bun.Ident("status.id"), status.InReplyToID).
Scan(ctx)
Expand All @@ -131,7 +132,7 @@ func (s *statusDB) getStatus(ctx context.Context, lookup string, dbQuery func(*g

if status.BoostOfID != "" {
// Also load original boosted status
status.BoostOf = &gtsmodel.Status{}
status.BoostOf = new(gtsmodel.Status)
err := s.conn.NewSelect().Model(status.BoostOf).
Where("? = ?", bun.Ident("status.id"), status.BoostOfID).
Scan(ctx)
Expand All @@ -150,38 +151,38 @@ func (s *statusDB) getStatus(ctx context.Context, lookup string, dbQuery func(*g
// Set the status author account
status.Account, err = s.accounts.GetAccountByID(ctx, status.AccountID)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting status account: %w", err)
}

if id := status.BoostOfAccountID; id != "" {
// Set boost of status' author account
status.BoostOfAccount, err = s.accounts.GetAccountByID(ctx, id)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting boosted status account: %w", err)
}
}

if id := status.InReplyToAccountID; id != "" {
// Set in-reply-to status' author account
status.InReplyToAccount, err = s.accounts.GetAccountByID(ctx, id)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting in reply to status account: %w", err)
}
}

if len(status.EmojiIDs) > 0 {
// Fetch status emojis
status.Emojis, err = s.emojis.emojisFromIDs(ctx, status.EmojiIDs)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting status emojis: %w", err)
}
}

if len(status.MentionIDs) > 0 {
// Fetch status mentions
status.Mentions, err = s.mentions.GetMentions(ctx, status.MentionIDs)
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting status mentions: %w", err)
}
}

Expand Down

0 comments on commit 2eea3d5

Please sign in to comment.