Skip to content

Commit

Permalink
address comment 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Jun 10, 2024
1 parent e8c1e97 commit 16729d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions db/db_versioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func (b *BoltDBVersioned) Put(version uint64, ns string, key, value []byte) erro
if !b.db.IsReady() {
return ErrDBNotStarted
}
if len(value) == 0 {
return errors.Wrap(ErrInvalid, "not allowed to write nil value")
}
// check namespace
vn, err := b.checkNamespace(ns)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions db/db_versioned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func TestVersionedDB(t *testing.T) {
vn, err = db.checkNamespace(_bucket1)
r.NoError(err)
r.EqualValues(len(_k2), vn.keyLen)
// cannot write nil value
r.Equal(ErrInvalid, errors.Cause(db.Put(1, _bucket1, _k2, nil)))
km, err = db.checkKey(_bucket1, _k2)
r.Zero(km.firstVersion)
r.Zero(km.lastVersion)
Expand Down

0 comments on commit 16729d4

Please sign in to comment.