ssbc / jitdb

A database on top of a log with automatic index generation and maintenance
50 stars 7 forks source link

Seekers should not return undefined #210

Closed staltz closed 2 years ago

staltz commented 2 years ago

We typically return undefined if the field pointer was -1:

https://github.com/ssb-ngi-pointer/jitdb/blob/1dc806047567b1321fe52494f76b8cb01d846c4a/test/helpers.js#L41

This could be a problem if we later check the return value of these seeker functions, like here:

https://github.com/ssb-ngi-pointer/jitdb/blob/1dc806047567b1321fe52494f76b8cb01d846c4a/index.js#L315-L317

Shouldn't we always return -1 instead of undefined? Could this have been a source of bugs?

Note:

> ~-1
0

> !~-1
true

> ~0
-1

> !~0
false

> ~undefined
-1

> !~undefined
false

cc @arj03

arj03 commented 2 years ago

Yep, that looks incorrect