summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-06 02:03:50 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-12 16:20:05 -0700
commit8530a8b7b5f9f27bb5b5c319f285bb5a26470285 (patch)
tree3070f8e76149bc98aeef0572f5147c4d83084acf /lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go
parent2643592b0a802f3816a47f8d3425a8f3282eae3b (diff)
rebuildnodes: Rework to be clear about what went wrong when reading
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go
index b4ab645..9e3b144 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/keyio/keyio.go
@@ -152,13 +152,17 @@ func (o *Handle) readNode(ctx context.Context, laddr btrfsvol.LogicalAddr) *disk
return ref
}
-func (o *Handle) ReadItem(ctx context.Context, ptr ItemPtr) (item btrfsitem.Item, ok bool) {
- if o.graph.Nodes[ptr.Node].Level != 0 || ptr.Idx < 0 {
- return nil, false
+func (o *Handle) ReadItem(ctx context.Context, ptr ItemPtr) btrfsitem.Item {
+ if o.graph.Nodes[ptr.Node].Level != 0 {
+ panic(fmt.Errorf("should not happen: keyio.Handle.ReadItem called for non-leaf node@%v", ptr.Node))
+ }
+ if ptr.Idx < 0 {
+ panic(fmt.Errorf("should not happen: keyio.Handle.ReadItem called for negative item index: %v", ptr.Idx))
}
items := o.readNode(ctx, ptr.Node).Data.BodyLeaf
if ptr.Idx >= len(items) {
- return nil, false
+ panic(fmt.Errorf("should not happen: keyio.Handle.ReadItem called for out-of-bounds item index: index=%v len=%v",
+ ptr.Idx, len(items)))
}
- return items[ptr.Idx].Body, true
+ return items[ptr.Idx].Body
}