Skip to content

Commit 7d9be70

Browse files
committed
provide more in common permissions exception when opening a store
1 parent 000d4cf commit 7d9be70

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/src/store.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "bindings/bindings.dart";
44
import "bindings/helpers.dart";
55
import "modelinfo/index.dart";
66
import "model.dart";
7+
import "common.dart";
78

89
enum TxMode {
910
Read,
@@ -40,7 +41,23 @@ class Store {
4041
rethrow;
4142
}
4243
_cStore = bindings.obx_store_open(opt);
43-
checkObxPtr(_cStore, "failed to create store");
44+
45+
try {
46+
checkObxPtr(_cStore, "failed to create store");
47+
} on ObjectBoxException catch (e) {
48+
// Recognize common problems when trying to open/create a database
49+
// 10199 = OBX_ERROR_STORAGE_GENERAL
50+
if (e.nativeCode == 10199 && e.nativeMsg != null && e.nativeMsg.contains('Dir does not exist')) {
51+
// 13 = permissions denied, 30 = read-only filesystem
52+
if (e.nativeMsg.endsWith(' (13)') || e.nativeMsg.endsWith(' (30)')) {
53+
final msg = e.nativeMsg +
54+
" - this usually indicates a problem with permissions; if you're using Flutter you may need to use " +
55+
"getApplicationDocumentsDirectory() from the path_provider package, see example/README.md";
56+
throw ObjectBoxException(dartMsg: e.dartMsg, nativeCode: e.nativeCode, nativeMsg: msg);
57+
}
58+
}
59+
rethrow;
60+
}
4461
}
4562

4663
/// Closes this store.

0 commit comments

Comments
 (0)