1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Validate recently added change just in case

This commit is contained in:
mcrakhman 2024-11-29 13:46:35 +01:00
parent 16ef198c76
commit f9a84f23f9
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B

View file

@ -235,11 +235,19 @@ func (ot *objectTree) AddContentWithValidator(ctx context.Context, content Signa
oldHeads = append(oldHeads, ot.tree.Heads()...)
objChange, rawChange, err := ot.changeBuilder.Build(payload)
if err != nil {
return
}
// validating the change just in case to avoid possible bugs
err = ot.validateTree([]*Change{objChange})
if err != nil {
err = fmt.Errorf("error validating added change: %w", err)
return
}
if content.IsSnapshot {
// clearing tree, because we already saved everything in the last snapshot
ot.tree = &Tree{}
}
if validator != nil {
err = validator(rawChange)
if err != nil {