Im not sure how to reproduce the problem as it has something to do with what hive Wrote to the file, I am unable to read the file now.
Running await Hive.openBox("state", encryptionKey: key) works perfectly 99% of the time. However after writing to the data this error is now being thrown when I try to open the box.
E/flutter ( 3422): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: RangeError: Value not in range: -4
E/flutter ( 3422): #0 _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:4623:5)
E/flutter ( 3422): #1 _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1929:5)
E/flutter ( 3422): #2 new Uint8List.view (dart:typed_data:845:19)
E/flutter ( 3422): #3 BinaryReaderImpl.peekBytes
package:hive/…/binary/binary_reader_impl.dart:68
E/flutter ( 3422): #4 framesFromBytes
package:hive/…/binary/frames_from_bytes.dart:24
E/flutter ( 3422): #5 FrameIoHelper.framesFromFile
package:hive/…/io/frame_io_helper.dart:57
E/flutter ( 3422): <asynchronous suspension>
E/flutter ( 3422): #6 StorageBackendVm.initialize
package:hive/…/backend/storage_backend_vm.dart:98
E/flutter ( 3422): <asynchronous suspension>
E/flutter ( 3422): #7 BoxBase.initialize
package:hive/…/box/box_base.dart:86
E/flutter ( 3422): #8 HiveImpl.openBox
package:hive/src/hive_impl.dart:83
E/flutter ( 3422): <asynchronous suspension>
E/flutter ( 3422): #9 MyGuideStorage.init
package:app/util/myguide_storage.dart:48
E/flutter ( 3422): <asynchronous suspension>
E/flutter ( 3422): #10 main
package:app/main.dart:21
E/flutter ( 3422): #11 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:229:25)
E/flutter ( 3422): #12 _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 3422): #13 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 3422): #14 _runZoned (dart:async/zone.dart:1516:10)
E/flutter ( 3422): #15 runZoned (dart:async/zone.dart:1500:12)
E/flutter ( 3422): #16 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:221:5)
E/flutter ( 3422): #17 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
E/flutter ( 3422): #18 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I assume that wiping the data again will fix it, but i would like to know what exactly im writing that is causing this to happen or possibly a fix. I'll add to this issue if I manage to find a way to reproduce it.
Thanks for reporting this. Does the error happen for a specific file or does it happen even after you removed it?
If it is a specific file and if it is only a test database, it would be really helpful if you could send it to me...
Or if you find a way to reproduce this issue it would help even more ;)
No, after i have cleared the app's storage / reinstall it does not happen anymore.
I have reproduced the problem after using Box.clear(). After running that, I cannot use the box again for some reason. Though the issue doesnt happen while the box remains open.
After relaunching the app or re-opening the now cleared box is when the exception above is thrown.
Thanks for your great help! I found the issue and I'll fix it with the next beta version. Until that you can switch to the stable version to fix the problem.
No problem, mid implementation phase. Thanks for the snappy response times!
I have the same problem, i'm waiting for the fix!
@gabdsg Do you just see the same error or are you also on version 1.1.0-beta and use the clear() method?
@leisim I'm also in version 1.1.0-beta, i don't user clear()
@gabdsg Do you have some code to reproduce the issue?
@leisim No, i can't reproduce the issue...
@gabdsg Okay thanks... Please report if you have new insights :+1:
@leisim I see this log Recovering corrupted box then next time RangeError: Value not in range: -4 but still no idea why
@gabdsg Is it reproducible or does it happen randomly?
@leisim It happens many times but I can't reproduce it... just happens
@leisim maybe I restart the app when is writing? there any way to remove the corrupted box without using Hive.openBox?
I've seen this happened many times on my physical devices, usually after I left the phone charging for a long time (when other apps are updated).
P/S: Only on physical devices. Never have I seen it happened on simulator.
For me it only happens in the simulator, I didn't test it on a physical device.
I've seen this happened many times on my physical devices, usually after I left the phone charging for a long time (when other apps are updated).
Also on 1.1.0?
there any way to remove the corrupted box without using Hive.openBox
You can just remove the file but this should never happen...
whoops I'm currently on 1.0.0. I will upgrade to 1.1.0 and report back later.
Edit: It may take a few days since I can't force reproduce the issue.
happened today on Android emulator after I hot-restarted the app. Version: 1.1.0-beta
E/flutter (21115): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: RangeError: Value not in range: -4
E/flutter (21115): #0 _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:4623:5)
E/flutter (21115): #1 _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1929:5)
E/flutter (21115): #2 new Uint8List.view (dart:typed_data:845:19)
E/flutter (21115): #3 BinaryReaderImpl.peekBytes (package:hive/src/binary/binary_reader_impl.dart:68:22)
E/flutter (21115): #4 framesFromBytes (package:hive/src/binary/frames_from_bytes.dart:24:29)
E/flutter (21115): #5 FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:57:12)
E/flutter (21115): <asynchronous suspension>
E/flutter (21115): #6 StorageBackendVm.initialize (package:hive/src/backend/storage_backend_vm.dart:98:25)
E/flutter (21115): <asynchronous suspension>
E/flutter (21115): #7 BoxBase.initialize (package:hive/src/box/box_base.dart:86:20)
E/flutter (21115): #8 HiveImpl.openBox (package:hive/src/hive_impl.dart:83:17)
E/flutter (21115): <asynchronous suspension>
E/flutter (21115): #9 _openBoxes (package:birdy/main_delegate.dart:76:10)
E/flutter (21115): #10 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
E/flutter (21115): #11 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (21115): #12 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (21115): #13 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter (21115): #14 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter (21115): #15 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter (21115): #16 Future._completeWithValue (dart:async/future_impl.dart:522:5)
E/flutter (21115): #17 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
E/flutter (21115): #18 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
E/flutter (21115): #19 getApplicationDocumentsDirectory (package:path_provider/path_provider.dart)
E/flutter (21115): #20 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
E/flutter (21115): #21 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (21115): #22 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (21115): #23 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter (21115): #24 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter (21115): #25 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter (21115): #26 Future._completeWithValue (dart:async/future_impl.dart:522:5)
E/flutter (21115): #27 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
E/flutter (21115): #28 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
E/flutter (21115): #29 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart)
E/flutter (21115): #30 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
E/flutter (21115): #31 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (21115): #32 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (21115): #33 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter (21115): #34 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter (21115): #35 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter (21115): #36 Future._completeWithValue (dart:async/future_impl.dart:522:5)
E/flutter (21115): #37 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:552:7)
E/flutter (21115): #38 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (21115): #39 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (21115): #40 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (21115): #41 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (21115): #42 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (21115): #43 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
Please try version 1.1.0-beta2 it should fix the problem.
The original issue has been completely resolved when switching to 1.1.0-beta2 and attempting multiple ways to clear and reuse the data.
I can now clear all data in specific hives (i.e. a download cache) while keeping say... access token information, and as expected it does what it should. Thanks!
Also i have only been testing on physical devices, Not simulators, and it happens on physical devices. if that helps anyone.
Thanks for confirming it works. If anyone has issues on versions 1.1.0-beta2 or later, please open another issue.
Most helpful comment
Please try version
1.1.0-beta2it should fix the problem.