isar / isar/hive

HiveError: To use this list, you have to open the box...

Open
#450 9 comments 0 reactions 1 assignee Claimed by @simc View on GitHub
needs-author-feedback problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
Problem is happening on the web platform.
1. Application startup is the first time the two boxes in question are created (1 Async & 1 Sync).
- Box names contain a fixed prefix and a 9 char string (based on some id).
- for example nod-f71f6ff8 & ent-f71f6ff8
2. If the boxes are empty they are populated with some with sample data.
- This works fine, and it's so fast.
- After this point, we can read and write to the boxes no problems.
3. If the user refreshed the browser that is when **_HiveError: To use this list, you have to open the box "nod-f71f6ff8" first_** is thrown.

**Code sample**
1. TypeAdapters registered in main.
2. Code below is called before the material app
```dart
Future entityStoreForNamespace(String nsUid, Clock clock) async {
var name = 'ent-${nsUid.substring(0, 8)}';
var box = Hive.isBoxOpen(name)
? Hive.lazyBox(name)
: await Hive.openLazyBox(name).catchError(
(e) => print('** catching -> HiveError: To use this list.. $e'));
return EntityStore(
asyncPersistor: AsyncPersistor(
hiveStore: box,
onNotFoundBuilder: (key) => Entity.forFailedGet(key),
serializers: primitiveSerializers),
clock: clock);
}
```

and one for the sync box is pretty much the same.

```dart
Future nodeStoreForNamespace(String nsUid, Clock clock) async {
var name = 'nod-${nsUid.substring(0, 8)}';
var box = Hive.isBoxOpen(name)
? Hive.box(name)
: await Hive.openBox(name).catchError(
(e) => print('** catching -> HiveError: To use this list.. $e'));
return await NodeStore(
syncStore: SyncPersistor(
hiveStore: await box,
onNotFoundBuilder: (key) => Node.forFailedGet(key)),
clock: clock);
}

```
Both `````` and `````` extend ``````

The print statement is where it is caught and the site appears to be inside ```hive_list_impl.dart``` in particular the getting for the box [line 54](https://github.com/hivedb/hive/blob/9ce84d366590a6d324f7c34a035144b8fd66255d/hive/lib/src/object/hive_list_impl.dart#L54). As to why? I can not work it out.

1. Can confirm that both boxes are actually there in the browser. (Using chrome and not using incog mode).
2. Can confirm if I call ```Hive.boxExist``` the indexed exist and they are not open on the refresh 'As expected'.

_* Note this stack track is for the Sync box with called before the Async lazy box._

```stack
Error: HiveError: To use this list, you have to open the box "nod-f71f6ff8" first.
at Object.throw_ [as throw] (http://localhost:50572/dart_sdk.js:4328:11)
at HiveListImpl.lazy.get box [as box] (http://localhost:50572/packages/hive/src/box/lazy_box_impl.dart.lib.js:1913:23)
at HiveListImpl.lazy.get delegate [as delegate] (http://localhost:50572/packages/hive/src/box/lazy_box_impl.dart.lib.js:1938:32)
at HiveListImpl.lazy.cast (http://localhost:50572/packages/hive/src/util/delegating_list_view_mixin.dart.lib.js:84:21)
at http://localhost:50572/packages/decdeck/model/state/graph/graph.dart.lib.js:751:93
at graph.NodeAdapter.new.read (http://localhost:50572/packages/decdeck/model/state/graph/graph.dart.lib.js:756:9)
at binary_reader_impl.BinaryReaderImpl.new.read (http://localhost:50572/packages/hive/src/box/lazy_box_impl.dart.lib.js:1501:35)
at storage_backend_js.StorageBackendJs.new.decodeValue (http://localhost:50572/packages/hive/src/box/lazy_box_impl.dart.lib.js:1628:27)
at MappedListIterable.new.elementAt (http://localhost:50572/dart_sdk.js:21541:25)
at ListIterator.new.moveNext (http://localhost:50572/dart_sdk.js:21335:55)
at JsIterator.next (http://localhost:50572/dart_sdk.js:5997:21)
at storage_backend_js.StorageBackendJs.new.initialize (http://localhost:50572/packages/hive/src/box/lazy_box_impl.dart.lib.js:1685:20)
at initialize.next ()
at http://localhost:50572/dart_sdk.js:37593:33
at _RootZone.runUnary (http://localhost:50572/dart_sdk.js:37447:58)
at _FutureListener.thenAwait.handleValue (http://localhost:50572/dart_sdk.js:32424:29)
at handleValueCallback (http://localhost:50572/dart_sdk.js:32971:49)
at Function._propagateToListeners (http://localhost:50572/dart_sdk.js:33009:17)
at _Future.new.[_completeWithValue] (http://localhost:50572/dart_sdk.js:32852:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:50572/dart_sdk.js:32874:35)
at Object._microtaskLoop (http://localhost:50572/dart_sdk.js:37708:13)
at _startMicrotaskLoop (http://localhost:50572/dart_sdk.js:37714:13)
at http://localhost:50572/dart_sdk.js:33226:9

```

**Version**
- Flutter (Channel beta, 1.22.0, on Mac OS X 10.15.7 19H2, locale en-AU)
- hive: ^1.4.4

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.