phonegap/phonegap-wp7 — Issue #29: Attempting to read a file which doesn't exist doesn't call failure function.
Author: eeyrcr
Created: 2011-10-15 22:13:17+00:00
State: open

I am attempting to read a text file which doesn't exist, using the code below. I would expect my 'fileError' function to get called, but it isn't.

When I run the code, I see the message 'getFile Called' in my 'Message' div, but don't then get the failure message...

$(function () {
document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {
// Look for some stored credentials
requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fileError);
}

function gotFileSystem(fs) {
fs.root.getFile("config.txt", { create: false }, gotFile, fileError);
$('div#Message').html('getFile called.');
}

function gotFile(f) {
var reader = new FileReader();

$('div#Message').html('File Found');

reader.onloadend = function (evt) {
$('div#Message').html('File Loaded');
};

reader.readAsText(f);
}

function fileError(evt) {
$('div#Message').html('File Not Loaded: ' + evt.target.error.code);
console.log(evt.target.error.code);
}