algolia / algoliasearch-helper-flutter

⚡️ Building block to create instant-search applications with Flutter
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/flutter/
Other
22 stars 15 forks source link

Unhandled Exception: FileSystemException: Creation failed, path = 'algolia' (OS Error: Read-only file system, errno = 30) #84

Closed Patrick386 closed 1 year ago

Patrick386 commented 1 year ago

When I run the app on the iOS emulator(iPhone 14), I encounter the following error. Do you know how to resolve it? Just to note, there are no issues when running it on the web.

algolia_helper_flutter: ^0.3.2

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Creation failed, path = 'algolia' (OS Error: Read-only file system, errno = 30)
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:114:9)
<asynchronous suspension>
#2      BackendManager.open (package:hive/src/backend/vm/backend_manager.dart:34:7)
<asynchronous suspension>
#3      HiveImpl._openBox (package:hive/src/hive_impl.dart:101:21)
<asynchronous suspension>
#4      HiveImpl.openBox (package:hive/src/hive_impl.dart:142:12)
<asynchronous suspension>
#5      UserTokenStorage.read (package:algolia_insights/src/user_token_storage.dart:101:17)
<asynchronous suspension>
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Creation failed, path = 'algolia' (OS Error: Read-only file system, errno = 30)
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:114:9)
<asynchronous suspension>
#2      BackendManager.open (package:hive/src/backend/vm/backend_manager.dart:34:7)
<asynchronous suspension>
#3      HiveImpl._openBox (package:hive/src/hive_impl.dart:101:21)
<asynchronous suspension>
#4      HiveImpl.openBox (package:hive/src/hive_impl.dart:142:12)

Flutter doctor

[✓] Flutter (Channel stable, 3.10.4, on macOS 13.0 22A380 darwin-arm64 (Rosetta), locale ko-KR)
    • Flutter version 3.10.4 on channel stable at /Users/patrick386/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 682aa387cf (4 days ago), 2023-06-05 18:04:56 -0500
    • Engine revision 2a3401c9bb
    • Dart version 3.0.3
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/patrick386/Library/Android/sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.4)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 74.0.2
    • Dart plugin version 222.4582

[✓] VS Code (version 1.71.1)
    • VS Code at /Users/patrick386/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.58.0

[✓] VS Code (version 1.75.1)
    • VS Code at /Users/patrick386/Visual Studio Code.app/Contents
    • Flutter extension version 3.58.0

[✓] Connected device (3 available)
    • iPhone 14 (mobile) • 35FC9EF0-A1B7-4E3F-988B-6488783A5868 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)    • macos                                • darwin-arm64   • macOS 13.0 22A380 darwin-arm64 (Rosetta)
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 114.0.5735.106

[✓] Network resources
    • All expected network resources are available.
deogw commented 1 year ago

I got the same error, after upgrading Flutter to the 3.10.2 version.

This is stack trace from crashanalytics :

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: FileSystemException: Creation failed, path = 'algolia' (OS Error: Read-only file system, errno = 30) at ._rootRunUnary(dart:async) at BackendManager.open(backend_manager.dart:34) at HiveImpl._openBox(hive_impl.dart:101) at HiveImpl.openBox(hive_impl.dart:142) at UserTokenStorage.read(user_token_storage.dart:101)

nerder commented 1 year ago

This is caused by an issue in how hive is used in https://github.com/algolia/algoliasearch-helper-flutter/blob/main/insights_dart/lib/src/user_token_storage.dart

It seems like that when you create an HitsSearcher you are also forced to instantiate Insight even if you don't actually use it.

The fix is to add a temporary writable directory before opening the box. I'll PR that so that later people can point to that version for the fix.

nerder commented 1 year ago

Similar to this issue: https://github.com/hivedb/hive/issues/40

VladislavFitz commented 1 year ago

Hi @Patrick386, @deogw , Thank you for reporting this issue.
I'm actively working to find a solution and fix this as soon as possible.

nerder commented 1 year ago

That's great.

It seems like the solution is simply to do this:

  Future<Box> get _box async {
    final tmpDir = await getTemporaryDirectory();
    return Hive.openBox(_boxName, path: '${tmpDir.path}/$_boxPath');
  }

instead of this:

https://github.com/algolia/algoliasearch-helper-flutter/blob/3e9c5732b61f9749dee0ce1d6fa7d3232a9ae7f6/insights_dart/lib/src/user_token_storage.dart#L41

I've forked the repo and I'm testing this right now.

nerder commented 1 year ago

I've tested it locally and the error is not triggered anymore, as a temporary workaround until the maintainer ship this code you can point at my commit:

pubspec.yml

dependency_overrides:
  algolia_insights:
    git:
      url: https://github.com/nerder/algoliasearch-helper-flutter/
      ref: 1f90cc5095527c43ac8820415dfe24b2c937d37f
      path: insights_dart
EglerEnrique commented 1 year ago

Same error

mohyghb commented 1 year ago

Same error, is there a timeline as to when the fix will be merged to main and published?