hive
hive copied to clipboard
HiveError: This should not happen.
Steps to Reproduce We load a light REDUX state on each startup of our app. Suddenly, without any specific issue, the load process failed and following exception is thrown.
E/flutter ( 6464): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: HiveError: This should not happen. Please open an issue on GitHub.
E/flutter ( 6464): #0 BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:250)
E/flutter ( 6464): #1 FrameHelper.framesFromBytes (package:hive/src/binary/frame_helper.dart:21)
E/flutter ( 6464): #2 FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:42)
E/flutter ( 6464): <asynchronous suspension>
E/flutter ( 6464): #3 StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:86)
E/flutter ( 6464): <asynchronous suspension>
E/flutter ( 6464): #4 HiveImpl._openBox (package:hive/src/hive_impl.dart:111)
E/flutter ( 6464): <asynchronous suspension>
E/flutter ( 6464): #5 HiveImpl.openBox (package:hive/src/hive_impl.dart:139)
E/flutter ( 6464): <asynchronous suspension>
E/flutter ( 6464): #6 LocalPersistor.setup (package:maximiliana/core/redux/persistor.dart:23)
E/flutter ( 6464): <asynchronous suspension>
E/flutter ( 6464): #7 StoreService._init (package:maximiliana/core/services/store_service.dart:23)
E/flutter ( 6464): <asynchronous suspension>
E/flutter ( 6464): #8 StoreService.setup (package:maximiliana/core/services/store_service.dart:46)
E/flutter ( 6464): <asynchronous suspension>
E/flutter ( 6464): #9 StartupService._startCoreServices.<anonymous closure> (package:maximiliana/core/services/startup_service.dart:108)
E/flutter ( 6464): <asynchronous suspension>
Code sample We manage persistence as follows:
class LocalPersistor extends Persistor<AppState> {
static const String HIVE_APPSTATE_BOX = 'maximiliana-appstate';
static Future<LocalPersistor> setup() async {
await Hive.initFlutter();
Hive.registerAdapter(ContactAdapter());
Hive.registerAdapter(AppStateAdapter());
Hive.registerAdapter(DeviceStatusAdapter());
Hive.registerAdapter(ExternalAppAdapter());
Hive.registerAdapter(AnswerSettingsAdapter());
Hive.registerAdapter(ContactsPolicyAdapter());
await Hive.openBox(HIVE_APPSTATE_BOX);
getLogger().v('[LOCAL PERSISTOR] Persistor is ready');
return LocalPersistor();
}
@override
Future<void> deleteState() async {
await Hive.box(HIVE_APPSTATE_BOX).delete('appstate');
}
@override
Future<void> persistDifference({
AppState lastPersistedState,
AppState newState,
}) async {
if (lastPersistedState == null || newState != lastPersistedState) {
await Hive.box(HIVE_APPSTATE_BOX).put('appstate', newState);
}
}
@override
Future<AppState> readState() async {
return await Hive.box(HIVE_APPSTATE_BOX).get('appstate');
}
}
Version
- Platform: Android
- Flutter version: Flutter (Channel stable, 2.10.4, on macOS 12.3.1 21E258 darwin-arm, locale es-ES)
- Hive version:
^2.0.2and^1.0.0(hive_flutter)
I have the same problem hive_flutter: ^1.1.0