• Okay, apologies in advance for putting out a post without clearly reproducible code. But maybe someone has seen this before and can help.

    I am able to write and delete to Bangle JS using the StorageFile api.

    Currently my code displays ERROR on screen when my file has tried to write over an MB and failed. Thereafter it doesn't try to write anymore until the file has been dowloaded and the old file deleted. Following are bits of code that do these things

    Bangle.AppLog = {
                currentFile: null,
                shardCount: 0,
                currentFileName: "",
                error: false,
                init: (filename) => {
                    Bangle.AppLog.currentFileName = filename;
                    try{
                        if(filename != null && filename != ''){
                            Bangle.AppLog.currentFile = require("Storage").open(filename, "a");
                            console.log("File created: " + filename);
                        }
                        else{
                            console.error("Log file name not provided");
                        }
                    }
                    catch(ex){
                        console.log("Failed to create file", ex);
                    }
                },
                write : (sentence) => {
                    if(Bangle.AppLog.error != true){
                        try{
                            Bangle.AppLog.currentFile.write(sentence­);   
                        }   
                        catch (ex){
                            console.log(ex);
                            Bangle.AppLog.currentFile = null;
                            Bangle.AppLog.error = true;
                        }              
                    }
                },
                clearLog: () => {
                    Bangle.AppLog.currentFile = null;
                    require("Storage").open(Bangle.AppLog.cu­rrentFileName, "w").erase();
                    Bangle.AppLog.error = false;
                },
                beginSync: () => {
                    var f = require('Storage').open(Bangle.AppLog.cu­rrentFileName, 'r');
                    var line = '';
                    while (line != null && line.indexOf('\xFF') == -1){
                        line = f.readLine();
                        if(line != null){
                            print(line);
                        }
                        else{
                            break;
                        }
                    }
                    print("<!-- finished sync -->");
                    f=null;
                }
            };
    

    Every so often (every 1 out of 3 tries) after I have deleted the old file by calling Bangle.AppLog.clearLog() from the WebIDE - the app will try to (re)create the file, (it doesn't throw any error when calling open(...)), but fails when trying to write to the file.

    >Bangle.Helper.size("fitclock.log");
    0
    =undefined
    Trying to create new file:fitclock.log
    File created: fitclock.log
    Error: Error: Unable to find or create file
    Trying to create new file:fitclock.log
    File created: fitclock.log
    

    As seen from the above log entries to the console, init() doesn't throw an error but the first write does.

    Unfortunately, once the storage gets into this state, I cannot get Bangle to write to any file with any other name. Rebooting using "Button 1 & 2 press" doesn't help. I have to to Storage.eraseAll() to get back ability to write to file system again. All of them throw the same "Unable to find of create file" error.

    >
    >
    >
    >var f = require("Storage").open("test", "a");
    =StorageFile: {
      name: "test",
      chunk: 1, offset: 0, addr: 0, mode: 97 }
    >f.write("Testing");
    Uncaught Error: Unable to find or create file
     at line 1 col 18
    f.write("Testing");
                     ^
    > 
    

    It is worth noting, even though StorageFile.open(...) did not throw an error, the file doesn't exist or is not recognised in the file WebIDE's file browser (ref to attached image).

    I looked through the entire repository and there is only one instance of the error message Unable to find or create file and it seems to be only present here

    That led me to the open issue... can't tell for sure but these two might be related?

    P.S. Interesting side note... there seems to be very little disk space left for real or so Bangle thinks... So the files probably didn't get deleted and their space reclaimed? That would explain the 1/3 frequency. That certainly explains why things work after eraseAll... Hmm... what am I doing wrong with my clearLog function?

    >require("Storage").getFree();
    =3144
    

    1 Attachment

    • Screen Shot 2020-03-08 at 11.25.09 PM.png
About

Avatar for PiOfThings @PiOfThings started