Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unhandled exception: Error: Tried to operate on a nonexistent element.

Looking for a bit of help wit this error message.

 

It is happening when I attempt to save the data on unload.

// Save settings to the filesystem
    function saveSettings() {
    let json_data = {};
    console.log("Saving data to file")

    json_data.dateFormat = dformat.text;  <<<< Exception Occurs>>>>

    fs.writeFileSync('settings.cbor', json_data, 'cbor');
    console.log("All settings saved")

}

 

What is odd is that I am using the exact same code in other apps/faces and don't have an issue. I have Google'd the hell out of the error and am unable to find anything. 

Best Answer
0 Votes
1 REPLY 1

I started getting this error message a few SDKs ago. I gather that the sequence in which an app is destroyed on closing got changed; now, the gui seems to get dismantled before the code. (Or perhaps it's a race condition, but that doesn't help much.)

 

I can get this error when updating elements in a setInterval event. The event keeps firing even after the elements are no longer valid when the app is closing. When the only thing at stake is what's on the screen, it doesn't matter.

 

In your case, I'd save the settings whenever they change on the watch. Not only will this avoid the problem, but it will result in a slightly quicker transition between apps (when there's a lot going on already).

Peter McLennan
Gondwana Software
Best Answer
0 Votes