One of the issues I've run into with PhoneGap is dealing with constants. For example, today I'm doing my first work with the file system. I ran into an issue using one of the methods. My error handler was called with the helpful value of:
code:1
Oh. Of course. Error code 1. Well, everyone knows what that is, right? If you check the docs, you see this for FileError:
Ok, that's not helpful. You can clearly see the types of errors, but nothing here indicates what is what.
Luckily I ran into this before (with the SQL stuff I believe) and I remembered that if you simply open up phonegap.js (the JavaScript file you include in every PhoneGap project), you can quickly search for your error object (in my case, FileError), and come across the code:
// Added by this specification
FileError.NOT_READABLE_ERR = 4;
FileError.ENCODING_ERR = 5;
FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
FileError.INVALID_STATE_ERR = 7;
FileError.SYNTAX_ERR = 8;
FileError.INVALID_MODIFICATION_ERR = 9;
FileError.QUOTA_EXCEEDED_ERR = 10;
FileError.TYPE_MISMATCH_ERR = 11;
FileError.PATH_EXISTS_ERR = 12;
// File error codes
// Found in DOMException
FileError.NOT_FOUND_ERR = 1;
FileError.SECURITY_ERR = 2;
FileError.ABORT_ERR = 3;
If there is an automatic way to translate that error w/o enumerating over FileError, I don't know. In my case, I just needed this documented.
Archived Comments
Well, you can just make a comparison without referencing the error code's value:
if (fail.code == FileError.NOT_FOUND_ERR) {
// ...
}
Or
switch(fail.code) {
case FileError.NOT_FOUND_ERR:
// ...
For me, it wasn't a "using" issue, but a documentation issue. What you recommend is definiltey how I'd use it in the code, but I needed help figuring out how even to get that code setup (if that distinction makes sense).
Hi All.. i'm developer. recenltly upgrade corvova 3.4.0 . I try getfile and receive err.code 1000 ... what's this?? :-(
FileManager.prototype.ReadAsTextFromFile = function (fileName, readDataCallBack) {
var that = this;
try {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(fileName, {create: false},
function (fileEntry) {
fileEntry.file(
function (file){
var reader = new FileReader();
// il risultato della onloadend ovvero evt.target.result viene
// assegnato alla callback, ora vai su relief_detail.js > getReliefDetail
reader.onloadend = readDataCallBack;
reader.readAsText(file);
}
, function(err){alert('ReadFile' + " fail: " + err.code);});
}
, function(err){alert('GetFile' + " fail: " + err.code);});
}, function(err){alert('FileSystem' + " fail: " + err.code);});
} catch (e) {
logError(e);
}
}
The last version of PhoneGap had a pretty big File IO change: http://www.raymondcamden.co...
Thanks Raymond, but I can not.. always error.code 1000 :-(
https://github.com/apache/c...
i try : cdvfile://localhost/persistent/" + my_file_path (android) (/scard/pippo.txt)
According to the source (https://github.com/apache/c... this is an unknown error. Not sure what to suggest. I haven't had a chance yet to try File stuff in the new builds.
I understand, Can you recommend a third-party plugins to manage file IO?
Well, the FileSystem plugin *does* work - I'd just keep digging. Or consider the PhoneGap Google group.