react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

Fails silently when using bad path

Open elliotsayes opened this issue 3 years ago • 4 comments

When creating MMKV with a bad path e.g.

const storage = new MMKV({
  id: 'storage',
  path: '/someillegalpath/data',
})

This call succeeds

storage.put('myKey', 'some data')

However the data is not actually stored

console.log(storage.getString('myKey'))
// LOG: undefined

As an aside would be nice to have some examples with valid paths or link to docs about what paths are allowed :) Or maybe export DocumentDir or something like react-native-fs?

elliotsayes avatar Oct 20 '22 21:10 elliotsayes

Oh that's interesting. Is there something being printed to Xcode Logs / Android Logcat?

mrousavy avatar Oct 24 '22 10:10 mrousavy

Ahh yes there is:

2022-10-25 10:29:26.434695+1300 Evertrove[99366:6190752] [W] <MemoryFile.cpp:273::mkPath> /mybadpath : Read-only file system
2022-10-25 10:29:26.434864+1300 Evertrove[99366:6190752] [I] <MMKV.cpp:234::mmkvWithID> prepare to load mmkv.default (id 0306af51b6f09612686a6fec90b5c7a7) from rootPath /mybadpath/file
2022-10-25 10:29:26.434977+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:94::open> fail to open [/mybadpath/file/mmkv.default], 2(No such file or directory)
2022-10-25 10:29:26.435093+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:94::open> fail to open [/mybadpath/file/mmkv.default], 2(No such file or directory)
2022-10-25 10:29:26.435196+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:208::reloadFromFile> fail to open:/mybadpath/file/mmkv.default, Undefined error: 0
2022-10-25 10:29:26.435316+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:94::open> fail to open [/mybadpath/file/mmkv.default.crc], 2(No such file or directory)
2022-10-25 10:29:26.435411+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:94::open> fail to open [/mybadpath/file/mmkv.default.crc], 2(No such file or directory)
2022-10-25 10:29:26.435481+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:208::reloadFromFile> fail to open:/mybadpath/file/mmkv.default.crc, Undefined error: 0
2022-10-25 10:29:26.435575+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:94::open> fail to open [/mybadpath/file/mmkv.default], 2(No such file or directory)
2022-10-25 10:29:26.435655+1300 Evertrove[99366:6190752] [E] <MemoryFile.cpp:208::reloadFromFile> fail to open:/mybadpath/file/mmkv.default, Undefined error: 0
2022-10-25 10:29:26.438928+1300 Evertrove[99366:6190752] [E] <MMKV_IO.cpp:74::loadFromFile> file [/mybadpath/file/mmkv.default] not valid
2022-10-25 10:29:26.441086+1300 Evertrove[99366:6190752] [javascript] { '0': 104,
  '1': 105,
  '2': 32,
  '3': 128,
  '4': 104,
  '5': 101,
  '6': 114,
  '7': 101 }
2022-10-25 10:29:26.441316+1300 Evertrove[99366:6190752] [W] <MMKV_IO.cpp:346::ensureMemorySize> [mmkv.default] file not valid
2022-10-25 10:29:26.442056+1300

I'll pay more attention to the iOS log when debugging 🕵️‍♂️ Still would be nice to see these bubble up to the JS log

elliotsayes avatar Oct 24 '22 21:10 elliotsayes

Still would be nice to see these bubble up to the JS log

No, lol that would be pretty annoying as it spams a lot. A native library logs to the native console.

fail to open [/mybadpath/file/mmkv.default], 2(No such file or directory)

But yea that's weird. I wonder why that doesn't throw.

mrousavy avatar Oct 25 '22 09:10 mrousavy

Does this issue still persist?

mrousavy avatar Jul 17 '23 11:07 mrousavy

Yes!

matinzd avatar Jul 04 '24 22:07 matinzd

Hey - I think this has been fixed in V3 beta.

mrousavy avatar Jul 22 '24 15:07 mrousavy