@bochaco I have now posted this on github: issue #91
I have a live app on Alpha2 which is behaving oddly, quite likely my fault, but possibly a bug in the API.
The issue is that while I am using
safeMutableData.getVersion() successfully most of the time, I can also reliably cause it to fail with an ‘invalid handle’ error, although the handle it reports as invalid is as expected, so I don’t know why it thinks it is invalid.
- Login to an account on Alpha2 and visit safe://litewrite.rsports - this is a simple note taking app which allows you to create notes offline or online, and syncs them to SAFE storage when online.
- Create a note (the app is offline at this stage), by clicking the ‘+’ top left, and entering text in the area just to the right. The first line of the text serves as a document title, and a menu entry will be added to the left, under the ‘+’.
- Connect to SAFE by clicking the SAFE icon in the top right of the litewrite display. Notice the activity in the debug console: you’ll see the
appHandle and a delay while you authorise litewrite, after which the handle for the MD container, and an ‘emulate as NFS’ handle are printed for later reference by a function called
_getMdHandle (search for the latter in the console output if you can’t find the messages).
- In the console you will see lots of activity following connection, and at this point I believe there will not be any errors (but I can’t be sure of that as I have made some code changes since I had a clean account to play with). You will also notice that so long as you remain connected, the console shows a flurry of output every ten seconds, when the RS.js core of the app attempts to sync local storage (IndexDB entries) with files it creates in the root container, in /remotestorage/documents/notes/. This includes stuff to show me that my code is accessing the container and generating a directory listing by filtering the results of
window.safeMutableData.getEntries(self.mdRoot) - which is successfully using the handle which the error reports as invalid. See _getFolder implementation for that call to
window.safeMutableData.getEntries(self.mdRoot). Notice that
_getFolder is successfully calling the function that is later generating an error (
window.safeMutableData.getVersion(self.mdRoot)) and with the same MD handle.
- Set a breakpoint (if you like) at the line in litewrite.min.js containing the text ‘safeMutableData.getVersion() FAILED’
- Create a new note (click the ‘+’) and type a few characters. This will force an immediate attempt to sync with the network and is when I get the error. Repeat this until you get the error in the console (or hit that breakpoint). For me I get it every time now.
I may be doing something wrong in how I’m using the API, or maybe I’m triggering a bug in it, or? I’m not really sure how to debug this without getting into the browser code and I’m not ready to do that! Any ideas, help appreciated. Thanks.
If anyone else want to try the above and report whether they get this error (or others) or not, please do, it may be helpful.
I apologise now for the structure of the code to any who open it - I’m still a newb on how best to use promises, handle errors etc. Tips gratefully received from everyone