mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-02 16:18:08 -06:00
[bugfix] Rework MultiError to wrap + unwrap errors properly (#2057)
* rework multierror a bit * test multierror
This commit is contained in:
parent
2cee8f2dd8
commit
e8a20f587c
24 changed files with 263 additions and 154 deletions
|
|
@ -20,7 +20,6 @@ package bundb
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -255,7 +254,7 @@ func (a *accountDB) getAccount(ctx context.Context, lookup string, dbQuery func(
|
|||
func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Account) error {
|
||||
var (
|
||||
err error
|
||||
errs = make(gtserror.MultiError, 0, 3)
|
||||
errs = gtserror.NewMultiError(3)
|
||||
)
|
||||
|
||||
if account.AvatarMediaAttachment == nil && account.AvatarMediaAttachmentID != "" {
|
||||
|
|
@ -265,7 +264,7 @@ func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Accou
|
|||
account.AvatarMediaAttachmentID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating account avatar: %w", err))
|
||||
errs.Appendf("error populating account avatar: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +275,7 @@ func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Accou
|
|||
account.HeaderMediaAttachmentID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating account header: %w", err))
|
||||
errs.Appendf("error populating account header: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -287,11 +286,15 @@ func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Accou
|
|||
account.EmojiIDs,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating account emojis: %w", err))
|
||||
errs.Appendf("error populating account emojis: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
if err := errs.Combine(); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *accountDB) PutAccount(ctx context.Context, account *gtsmodel.Account) error {
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ func (i *instanceDB) getInstance(ctx context.Context, lookup string, dbQuery fun
|
|||
func (i *instanceDB) populateInstance(ctx context.Context, instance *gtsmodel.Instance) error {
|
||||
var (
|
||||
err error
|
||||
errs = make(gtserror.MultiError, 0, 2)
|
||||
errs = gtserror.NewMultiError(2)
|
||||
)
|
||||
|
||||
if instance.DomainBlockID != "" && instance.DomainBlock == nil {
|
||||
|
|
@ -183,7 +183,7 @@ func (i *instanceDB) populateInstance(ctx context.Context, instance *gtsmodel.In
|
|||
instance.Domain,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(gtserror.Newf("error populating instance domain block: %w", err))
|
||||
errs.Appendf("error populating instance domain block: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,11 +194,15 @@ func (i *instanceDB) populateInstance(ctx context.Context, instance *gtsmodel.In
|
|||
instance.ContactAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(gtserror.Newf("error populating instance contact account: %w", err))
|
||||
errs.Appendf("error populating instance contact account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
if err := errs.Combine(); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *instanceDB) PutInstance(ctx context.Context, instance *gtsmodel.Instance) error {
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ func (l *listDB) GetListsForAccountID(ctx context.Context, accountID string) ([]
|
|||
func (l *listDB) PopulateList(ctx context.Context, list *gtsmodel.List) error {
|
||||
var (
|
||||
err error
|
||||
errs = make(gtserror.MultiError, 0, 2)
|
||||
errs = gtserror.NewMultiError(2)
|
||||
)
|
||||
|
||||
if list.Account == nil {
|
||||
|
|
@ -127,7 +127,7 @@ func (l *listDB) PopulateList(ctx context.Context, list *gtsmodel.List) error {
|
|||
list.AccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating list account: %w", err))
|
||||
errs.Appendf("error populating list account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,11 +139,15 @@ func (l *listDB) PopulateList(ctx context.Context, list *gtsmodel.List) error {
|
|||
"", "", "", 0,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating list entries: %w", err))
|
||||
errs.Appendf("error populating list entries: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
if err := errs.Combine(); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *listDB) PutList(ctx context.Context, list *gtsmodel.List) error {
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ func (r *relationshipDB) getFollow(ctx context.Context, lookup string, dbQuery f
|
|||
func (r *relationshipDB) PopulateFollow(ctx context.Context, follow *gtsmodel.Follow) error {
|
||||
var (
|
||||
err error
|
||||
errs = make(gtserror.MultiError, 0, 2)
|
||||
errs = gtserror.NewMultiError(2)
|
||||
)
|
||||
|
||||
if follow.Account == nil {
|
||||
|
|
@ -170,7 +170,7 @@ func (r *relationshipDB) PopulateFollow(ctx context.Context, follow *gtsmodel.Fo
|
|||
follow.AccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating follow account: %w", err))
|
||||
errs.Appendf("error populating follow account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,11 +181,15 @@ func (r *relationshipDB) PopulateFollow(ctx context.Context, follow *gtsmodel.Fo
|
|||
follow.TargetAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating follow target account: %w", err))
|
||||
errs.Appendf("error populating follow target account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
if err := errs.Combine(); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *relationshipDB) PutFollow(ctx context.Context, follow *gtsmodel.Follow) error {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
|
|
@ -129,7 +128,7 @@ func (s *statusDB) getStatus(ctx context.Context, lookup string, dbQuery func(*g
|
|||
func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status) error {
|
||||
var (
|
||||
err error
|
||||
errs = make(gtserror.MultiError, 0, 9)
|
||||
errs = gtserror.NewMultiError(9)
|
||||
)
|
||||
|
||||
if status.Account == nil {
|
||||
|
|
@ -139,7 +138,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.AccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status author: %w", err))
|
||||
errs.Appendf("error populating status author: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +149,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.InReplyToID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status parent: %w", err))
|
||||
errs.Appendf("error populating status parent: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +161,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.InReplyToID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status parent: %w", err))
|
||||
errs.Appendf("error populating status parent: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +172,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.InReplyToAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status parent author: %w", err))
|
||||
errs.Appendf("error populating status parent author: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -186,7 +185,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.BoostOfID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status boost: %w", err))
|
||||
errs.Appendf("error populating status boost: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +196,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.BoostOfAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status boost author: %w", err))
|
||||
errs.Appendf("error populating status boost author: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -209,7 +208,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.AttachmentIDs,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status attachments: %w", err))
|
||||
errs.Appendf("error populating status attachments: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +219,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.TagIDs,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status tags: %w", err))
|
||||
errs.Appendf("error populating status tags: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +230,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.MentionIDs,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status mentions: %w", err))
|
||||
errs.Appendf("error populating status mentions: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -242,11 +241,15 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
status.EmojiIDs,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status emojis: %w", err))
|
||||
errs.Appendf("error populating status emojis: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
if err := errs.Combine(); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) error {
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ func (s *statusFaveDB) GetStatusFavesForStatus(ctx context.Context, statusID str
|
|||
func (s *statusFaveDB) PopulateStatusFave(ctx context.Context, statusFave *gtsmodel.StatusFave) error {
|
||||
var (
|
||||
err error
|
||||
errs = make(gtserror.MultiError, 0, 3)
|
||||
errs = gtserror.NewMultiError(3)
|
||||
)
|
||||
|
||||
if statusFave.Account == nil {
|
||||
|
|
@ -159,7 +159,7 @@ func (s *statusFaveDB) PopulateStatusFave(ctx context.Context, statusFave *gtsmo
|
|||
statusFave.AccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status fave author: %w", err))
|
||||
errs.Appendf("error populating status fave author: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ func (s *statusFaveDB) PopulateStatusFave(ctx context.Context, statusFave *gtsmo
|
|||
statusFave.TargetAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status fave target account: %w", err))
|
||||
errs.Appendf("error populating status fave target account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,11 +181,15 @@ func (s *statusFaveDB) PopulateStatusFave(ctx context.Context, statusFave *gtsmo
|
|||
statusFave.StatusID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status fave status: %w", err))
|
||||
errs.Appendf("error populating status fave status: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
if err := errs.Combine(); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *statusFaveDB) PutStatusFave(ctx context.Context, fave *gtsmodel.StatusFave) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue