1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 14:07:02 +09:00

Add verbose errors

This commit is contained in:
mcrakhman 2024-05-16 13:28:32 +02:00
parent 1e65e90fe7
commit f8b49b36b5
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
3 changed files with 16 additions and 7 deletions

View file

@ -4,14 +4,16 @@ package objecttree
import (
"context"
"errors"
"fmt"
"sync"
"time"
"github.com/anyproto/any-sync/util/crypto"
"go.uber.org/zap"
"github.com/anyproto/any-sync/commonspace/object/acl/list"
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
"github.com/anyproto/any-sync/util/crypto"
"github.com/anyproto/any-sync/util/slice"
)
@ -124,6 +126,7 @@ func (ot *objectTree) rebuildFromStorage(theirHeads []string, newChanges []*Chan
ot.treeBuilder.Reset()
ot.tree, err = ot.treeBuilder.Build(theirHeads, newChanges)
if err != nil {
ot.tree = oldTree
return
}
@ -434,15 +437,20 @@ func (ot *objectTree) addRawChanges(ctx context.Context, changesPayload RawChang
err = ot.rebuildFromStorage(headsToUse, ot.newChangesBuf)
if err != nil {
// rebuilding without new changes
ot.rebuildFromStorage(nil, nil)
rebuildErr := ot.rebuildFromStorage(nil, nil)
if rebuildErr != nil {
log.Error("failed to rebuild", zap.String("treeId", ot.id), zap.Strings("heads", ot.Heads()), zap.Error(err))
}
return
}
addResult, err = ot.createAddResult(prevHeadsCopy, Rebuild, nil, changesPayload.RawChanges)
if err != nil {
// that means that some unattached changes were somehow corrupted in memory
// this shouldn't happen but if that happens, then rebuilding from storage
ot.rebuildFromStorage(nil, nil)
return
rebuildErr := ot.rebuildFromStorage(nil, nil)
if rebuildErr != nil {
log.Error("failed to rebuild after add result", zap.String("treeId", ot.id), zap.Strings("heads", ot.Heads()), zap.Error(err))
}
}
return
}
@ -463,7 +471,7 @@ func (ot *objectTree) addRawChanges(ctx context.Context, changesPayload RawChang
err = ot.validateTree(treeChangesAdded)
if err != nil {
rollback(treeChangesAdded)
err = ErrHasInvalidChanges
err = fmt.Errorf("%w: %w", ErrHasInvalidChanges, err)
return
}
addResult, err = ot.createAddResult(prevHeadsCopy, mode, treeChangesAdded, changesPayload.RawChanges)