1 // ==========================================================================
  2 // Project:   The M-Project - Mobile HTML5 Application Framework
  3 // Copyright: (c) 2010 M-Way Solutions GmbH. All rights reserved.
  4 //            (c) 2011 panacoda GmbH. All rights reserved.
  5 // Creator:   Sebastian
  6 // Date:      11.02.2011
  7 // License:   Dual licensed under the MIT or GPL Version 2 licenses.
  8 //            http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE
  9 //            http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE
 10 // ==========================================================================
 11 
 12 
 13 m_require('core/utility/logger.js');
 14 
 15 /**
 16  * @class
 17  *
 18  * The root object for Error objects
 19  *
 20  * M.Error encapsulates errors in The-M-Project.
 21  * Should be passed to error callbacks.
 22  *
 23  * 0-99:    general errors
 24  *
 25  * 100-199: Model and Validation errors
 26  *
 27  * 200-299:   WebSQL errors
 28  *
 29  * 300-400:   CouchDB errors
 30  *
 31  *
 32  * Constant                             Code    Situation
 33  * --------                             ----    ---------
 34  * M.ERR_UNDEFINED                      0       The reason for the error could not be clarified.
 35  * M.ERR_CONNECTION                     1       A connection to an external service could not be established
 36  *
 37  * M.ERR_VALIDATION_PRESENCE            100     A model record failed validation due to a property is not set but required to be.
 38  * M.ERR_VALIDATION_URL                 101     A model record failed validation due to a property does not represent a valid URL but is required to do so.
 39  * M.ERR_VALIDATION_PHONE               102     A model record failed validation due to a property does not represent a phone number but is required to do so.
 40  * M.ERR_VALIDATION_NUMBER              103     A model record failed validation due to a property is not of type number or represents a number but is required to do so.
 41  * M.ERR_VALIDATION_NOTMINUS            104     A model record failed validation due to a property contains a minus value but it is required to do not.
 42  * M.ERR_VALIDATION_EMAIL               105     A model record failed validation due to a property does not represent a valid eMail but is required to do so.
 43  * M.ERR_VALIDATION_DATE                106     A model record failed validation due to a property does not represent a valid date but is required to do so.
 44  *
 45  * M.ERR_MODEL_PROVIDER_NOT_SET         120     A data provider has not been set.
 46  *
 47  * M.ERR_WEBSQL_UNKNOWN                 200     The transaction failed for reasons unrelated to the database itself and not covered by any other error code.
 48  * M.ERR_WEBSQL_DATABASE                201     The statement failed for database reasons not covered by any other error code.
 49  * M.ERR_WEBSQL_VERSION                 202     The operation failed because the actual database version was not what it should be. For example, a statement found that the actual database version no longer matched the expected version of the Database or DatabaseSync object, or the Database.changeVersion() or DatabaseSync.changeVersion() methods were passed a version that doesn't match the actual database version.
 50  * M.ERR_WEBSQL_TOO_LARGE               203     The statement failed because the data returned from the database was too large. The SQL "LIMIT" modifier might be useful to reduce the size of the result set.
 51  * M.ERR_WEBSQL_QUOTA                   204     The statement failed because there was not enough remaining storage space, or the storage quota was reached and the user declined to give more space to the database.
 52  * M.ERR_WEBSQL_SYNTAX                  205     The statement failed because of a syntax error, or the number of arguments did not match the number of ? placeholders in the statement, or the statement tried to use a statement that is not allowed, such as BEGIN, COMMIT, or ROLLBACK, or the statement tried to use a verb that could modify the database but the transaction was read-only.
 53  * M.ERR_WEBSQL_CONSTRAINT              206     An INSERT, UPDATE, or REPLACE statement failed due to a constraint failure. For example, because a row was being inserted and the value given for the primary key column duplicated the value of an existing row.
 54  * M.ERR_WEBSQL_TIMEOUT                 207     A lock for the transaction could not be obtained in a reasonable time.
 55  * M.ERR_WEBSQL_PROVIDER_NO_DBHANDLER   208     No DBHandler, initialization did not take place or failed.
 56  * M.ERR_WEBSQL_BULK_NO_RECORDS         210     No Records given for bulk transaction
 57  *
 58  * M.ERR_COUCHDB_CONFLICT               300     A conflict occured while saving a document in CouchDB, propably caused by duplicate IDs
 59  * M.ERR_COUCHDB_DBNOTFOUND             301     The provided database could not be found.
 60  * M.ERR_COUCHDB_DBEXISTS               302     The db already exists and therefor cannot be created again.
 61  * M.ERR_COUCHDB_DOCNOTFOUND            303     No document was found for the provided ID in the database.
 62  *
 63  *
 64  *
 65  *
 66  * @extends M.Object
 67 */
 68 
 69 
 70 /**
 71  * A constant value for an undefined error.
 72  *
 73  * @type Number
 74  */
 75 M.ERR_UNDEFINED = 0;
 76 
 77 /**
 78  * A constant value for an error occuring when a connection to an external service could not be established.
 79  *
 80  * @type Number
 81  */
 82 M.ERR_CONNECTION = 1;
 83 
 84 /**
 85  * A model record failed validation due to a property is not set but required to be.
 86  *
 87  * @type Number
 88  */
 89 M.ERR_VALIDATION_PRESENCE = 100;
 90 
 91 /**
 92  * A model record failed validation due to a property does not represent a valid URL but is required to do so.
 93  *
 94  * @type Number
 95  */
 96 M.ERR_VALIDATION_URL = 101;
 97 
 98 /**
 99  * A model record failed validation due to a property does not represent a phone number but is required to do so.
100  *
101  * @type Number
102  */
103 M.ERR_VALIDATION_PHONE = 102;
104 
105 /**
106  * A model record failed validation due to a property is not of type number or represents a number but is required to do so.
107  *
108  * @type Number
109  */
110 M.ERR_VALIDATION_NUMBER = 103;
111 
112 /**
113  * A model record failed validation due to a property contains a minus value but it is required to do not.
114  *
115  * @type Number
116  */
117 M.ERR_VALIDATION_NOTMINUS = 104;
118 
119 /**
120  * A model record failed validation due to a property does not represent a valid eMail but is required to do so.
121  *
122  * @type Number
123  */
124 M.ERR_VALIDATION_EMAIL = 105;
125 
126 /**
127  * A model record failed validation due to a property does not represent a valid eMail but is required to do so.
128  *
129  * @type Number
130  */
131 M.ERR_VALIDATION_DATE = 106;
132 
133 /**
134  * A Data Provider was not set for a model.
135  *
136  * @type Number
137  */
138 M.ERR_MODEL_PROVIDER_NOT_SET = 120;
139 
140 
141 /* WebSQL Error Codes (see e.g. http://www.w3.org/TR/webdatabase/) */
142 /**
143  * A constant value for an error occuring with WebSQL.
144  * "The transaction failed for reasons unrelated to the database itself and not covered by any other error code."
145  * Error code in WebSQL specification: 0
146  *
147  * @type Number
148  */
149 M.ERR_WEBSQL_UNKNOWN = 200;
150 
151 /**
152  * A constant value for an error occuring with WebSQL.
153  * "The statement failed for database reasons not covered by any other error code."
154  * Error code in WebSQL specification: 1
155  *
156  * @type Number
157  */
158 M.ERR_WEBSQL_DATABASE = 201;
159 
160 /**
161  * A constant value for an error occuring with WebSQL.
162  * "The transaction failed for reasons unrelated to the database itself and not covered by any other error code."
163  * Error code in WebSQL specification: 2
164  *
165  * @type Number
166  */
167 M.ERR_WEBSQL_VERSION = 202;
168 
169 /**
170  * A constant value for an error occuring with WebSQL.
171  * "The statement failed because the data returned from the database was too large. The SQL "LIMIT" modifier might be useful to reduce the size of the result set."
172  * Error code in WebSQL specification: 3
173  *
174  * @type Number
175  */
176 M.ERR_WEBSQL_TOO_LARGE = 203;
177 
178 /**
179  * A constant value for an error occuring with WebSQL.
180  * "The statement failed because there was not enough remaining storage space, or the storage quota was reached and the user declined to give more space to the database."
181  * Error code in WebSQL specification: 4
182  *
183  * @type Number
184  */
185 M.ERR_WEBSQL_QUOTA = 204;
186 
187 /**
188  * A constant value for an error occuring with WebSQL.
189  * "The statement failed because of a syntax error, or the number of arguments did not match the number of ? placeholders in the statement, or the statement tried to use a statement that is not allowed, such as BEGIN, COMMIT, or ROLLBACK, or the statement tried to use a verb that could modify the database but the transaction was read-only."
190  * Error code in WebSQL specification: 5
191  *
192  * @type Number
193  */
194 M.ERR_WEBSQL_SYNTAX = 205;
195 
196 /**
197  * A constant value for an error occuring with WebSQL.
198  * "An INSERT, UPDATE, or REPLACE statement failed due to a constraint failure. For example, because a row was being inserted and the value given for the primary key column duplicated the value of an existing row."
199  * Error code in WebSQL specification: 6
200  *
201  * @type Number
202  */
203 M.ERR_WEBSQL_CONSTRAINT = 206;
204 
205 /**
206  * A constant value for an error occuring with WebSQL.
207  * "A lock for the transaction could not be obtained in a reasonable time."
208  * Error code in WebSQL specification: 7
209  *
210  * @type Number
211  */
212 M.ERR_WEBSQL_TIMEOUT = 207;
213 
214 /* following errors are WebSQL Data Provider errors. */
215 
216 /**
217  * A constant value for an error occuring when dbHandler does not exist in
218  * data provider. Reason: Initialization did not take place or failed.
219  *
220  * @type Number
221  */
222 M.ERR_WEBSQL_PROVIDER_NO_DBHANDLER = 208;
223 
224 /**
225  * A constant value for an error occuring with bulkSave operation in dataprovider.
226  * No Record array was passed to the method via the param obj.
227  *
228  * @type Number
229  */
230 M.ERR_WEBSQL_BULK_NO_RECORDS = 210;
231 
232 
233 /**
234  * A constant value for an error occuring when a conflict appears when saving a document in CouchDB. This is propably caused by duplicate IDs
235  *
236  * @type Number
237  */
238 M.ERR_COUCHDB_CONFLICT = 300;
239 
240 /**
241  * A constant value for an error occuring if the provided database could not be found
242  *
243  * @type Number
244  */
245 M.ERR_COUCHDB_DBNOTFOUND = 301;
246 
247 /**
248  * A constant value for an error occuring if a database that shall be created already exists
249  *
250  * @type Number
251  */
252 M.ERR_COUCHDB_DBEXISTS = 302;
253 
254 /**
255  * A constant value for an error occuring if a document could not be found
256  *
257  * @type Number
258  */
259 M.ERR_COUCHDB_DOCNOTFOUND = 303;
260 
261 M.Error = M.Object.extend(
262 /** @scope M.Error.prototype */ {
263     code: '',
264     msg: '',
265     errObj: null
266 });