diff --git a/Metadata.go b/Metadata.go index ef5eefe..8574a5a 100644 --- a/Metadata.go +++ b/Metadata.go @@ -3,6 +3,7 @@ package contented import ( "encoding/json" "errors" + "fmt" "log" "net/http" "os" @@ -62,9 +63,17 @@ func (this *Server) AddMetadata(m Metadata) (string, error) { err = this.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket(this.metadataBucket) - seq, _ := b.NextSequence() // cannot fail + seq, err := b.NextSequence() + if err != nil { + return fmt.Errorf("NextSequence: %w", err) + } shortRef = idToString(seq) - return tx.Bucket(this.metadataBucket).Put([]byte(shortRef), jb) + + if b.Get([]byte(shortRef)) != nil { + return fmt.Errorf("Next bucket sequence %d creates colliding ID %s", seq, shortRef) + } + + return b.Put([]byte(shortRef), jb) }) if err != nil { return "", err