@@ -65,10 +65,13 @@ func NewUnixFSHAMTShardWithPreload(ctx context.Context, substrate dagpb.PBNode,
65
65
return n , err
66
66
}
67
67
68
- traverse := n .Length ()
68
+ traverse , err := n .( * _UnixFSHAMTShard ). length ()
69
69
if traverse == - 1 {
70
70
return n , fmt .Errorf ("could not fully explore hamt during preload" )
71
71
}
72
+ if err != nil {
73
+ return n , err
74
+ }
72
75
73
76
return n , nil
74
77
}
@@ -261,9 +264,9 @@ func (n UnixFSHAMTShard) ListIterator() ipld.ListIterator {
261
264
262
265
// Length returns the length of a list, or the number of entries in a map,
263
266
// or -1 if the node is not of list nor map kind.
264
- func (n UnixFSHAMTShard ) Length () int64 {
267
+ func (n UnixFSHAMTShard ) length () ( int64 , error ) {
265
268
if n .cachedLength != - 1 {
266
- return n .cachedLength
269
+ return n .cachedLength , nil
267
270
}
268
271
maxPadLen := maxPadLength (n .data )
269
272
total := int64 (0 )
@@ -272,20 +275,34 @@ func (n UnixFSHAMTShard) Length() int64 {
272
275
_ , pbLink := itr .Next ()
273
276
isValue , err := isValueLink (pbLink , maxPadLen )
274
277
if err != nil {
275
- continue
278
+ return 0 , err
276
279
}
277
280
if isValue {
278
281
total ++
279
282
} else {
280
283
child , err := n .loadChild (pbLink )
281
284
if err != nil {
282
- continue
285
+ return 0 , err
283
286
}
284
- total += child .Length ()
287
+ cl , err := child .length ()
288
+ if err != nil {
289
+ return 0 , err
290
+ }
291
+ total += cl
285
292
}
286
293
}
287
294
n .cachedLength = total
288
- return total
295
+ return total , nil
296
+ }
297
+
298
+ // Length returns the length of a list, or the number of entries in a map,
299
+ // or -1 if the node is not of list nor map kind.
300
+ func (n UnixFSHAMTShard ) Length () int64 {
301
+ len , err := n .length ()
302
+ if err != nil {
303
+ return 0
304
+ }
305
+ return len
289
306
}
290
307
291
308
func (n UnixFSHAMTShard ) IsAbsent () bool {
0 commit comments