PhoneGap and constants

This post is more than 2 years old.

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:


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:

// File error codes // Found in DOMException FileError.NOT_FOUND_ERR = 1; FileError.SECURITY_ERR = 2; FileError.ABORT_ERR = 3;

// 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;

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.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA