PageRenderTime 31ms CodeModel.GetById 12ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ydn/db/base/error.js

https://bitbucket.org/ytkyaw/ydn-db
JavaScript | 483 lines | 227 code | 104 blank | 152 comment | 63 complexity | 69c000b7248cc635181b466a5710494a MD5 | raw file
  1/**
  2 *
  3 * @fileoverview Error classes for the database module.
  4 *
  5 */
  6
  7goog.provide('ydn.db.ConstraintError');
  8goog.provide('ydn.db.InternalError');
  9goog.provide('ydn.db.InvalidKeyException');
 10goog.provide('ydn.db.InvalidStateError');
 11goog.provide('ydn.db.NotFoundError');
 12goog.provide('ydn.db.ScopeError');
 13goog.provide('ydn.db.SecurityError');
 14goog.provide('ydn.db.TimeoutError');
 15goog.provide('ydn.db.VersionError');
 16
 17
 18
 19/**
 20 * Base class for custom error objects.
 21 * @param {*=} opt_msg The message associated with the error.
 22 * @constructor
 23 * @extends {Error}
 24 */
 25ydn.db.ConstraintError = function(opt_msg) {
 26
 27  // Ensure there is a stack trace.
 28  if (Error.captureStackTrace) {
 29    Error.captureStackTrace(this, ydn.db.ConstraintError);
 30  } else {
 31    this.stack = new Error().stack || '';
 32  }
 33
 34  if (opt_msg) {
 35    this.message = String(opt_msg);
 36  }
 37  this.name = 'ConstraintError';
 38};
 39goog.inherits(ydn.db.ConstraintError, Error);
 40
 41
 42/**
 43 *
 44 * @type {string}
 45 */
 46ydn.db.ConstraintError.prototype.name = 'ConstraintError';
 47
 48
 49if (goog.DEBUG) {
 50  /**
 51   * @inheritDoc
 52   */
 53  ydn.db.ConstraintError.prototype.toString = function() {
 54    return this.name + ': ' + this.message;
 55  };
 56}
 57
 58
 59
 60/**
 61 * Base class for custom error objects.
 62 * @param {*=} opt_msg The message associated with the error.
 63 * @constructor
 64 * @extends {Error}
 65 */
 66ydn.db.InvalidKeyException = function(opt_msg) {
 67
 68  // Ensure there is a stack trace.
 69  if (Error.captureStackTrace) {
 70    Error.captureStackTrace(this, ydn.db.InvalidKeyException);
 71  } else {
 72    this.stack = new Error().stack || '';
 73  }
 74
 75  if (opt_msg) {
 76    this.message = String(opt_msg);
 77  }
 78  this.name = 'ydn.db.InvalidKeyException';
 79};
 80goog.inherits(ydn.db.InvalidKeyException, Error);
 81
 82
 83if (goog.DEBUG) {
 84  /**
 85   * @inheritDoc
 86   */
 87  ydn.db.InvalidKeyException.prototype.toString = function() {
 88    return this.name + ': ' + this.message;
 89  };
 90}
 91
 92
 93
 94/**
 95 * Base class for custom error objects.
 96 * @param {*=} opt_msg The message associated with the error.
 97 * @constructor
 98 * @extends {Error}
 99 */
100ydn.db.VersionError = function(opt_msg) {
101
102  // Ensure there is a stack trace.
103  if (Error.captureStackTrace) {
104    Error.captureStackTrace(this, ydn.db.VersionError);
105  } else {
106    this.stack = new Error().stack || '';
107  }
108
109  if (opt_msg) {
110    this.message = String(opt_msg);
111  }
112  this.name = 'ydn.db.VersionError';
113};
114goog.inherits(ydn.db.VersionError, Error);
115
116
117/**
118 * @type {string} name of error.
119 */
120ydn.db.VersionError.prototype.name = 'ydn.db.VersionError';
121
122
123if (goog.DEBUG) {
124  /**
125   * @inheritDoc
126   */
127  ydn.db.VersionError.prototype.toString = function() {
128    return this.name + ': ' + this.message;
129  };
130}
131
132
133
134/**
135 * Base class for custom error objects.
136 * @param {*=} opt_msg The message associated with the error.
137 * @constructor
138 * @extends {Error}
139 */
140ydn.db.InternalError = function(opt_msg) {
141
142  // Ensure there is a stack trace.
143  if (Error.captureStackTrace) {
144    Error.captureStackTrace(this, ydn.db.InternalError);
145  } else {
146    this.stack = new Error().stack || '';
147  }
148
149  if (opt_msg) {
150    this.message = String(opt_msg);
151  }
152};
153goog.inherits(ydn.db.InternalError, Error);
154
155
156/**
157 * @type {string} name of error.
158 */
159ydn.db.InternalError.prototype.name = 'ydn.db.InternalError';
160
161
162
163/**
164 * Base class for custom error objects.
165 * @param {*=} opt_msg The message associated with the error.
166 * @constructor
167 * @extends {Error}
168 */
169ydn.db.ScopeError = function(opt_msg) {
170
171  // Ensure there is a stack trace.
172  if (Error.captureStackTrace) {
173    Error.captureStackTrace(this, ydn.db.ScopeError);
174  } else {
175    this.stack = new Error().stack || '';
176  }
177
178  if (opt_msg) {
179    this.message = String(opt_msg);
180  }
181  this.name = 'ydn.db.ScopeError';
182};
183goog.inherits(ydn.db.ScopeError, Error);
184
185
186
187/**
188 * Base class for custom error objects.
189 * @param {*=} opt_msg The message associated with the error.
190 * @constructor
191 * @extends {Error}
192 */
193ydn.db.InvalidStateError = function(opt_msg) {
194
195  // Ensure there is a stack trace.
196  if (Error.captureStackTrace) {
197    Error.captureStackTrace(this, ydn.db.InvalidStateError);
198  } else {
199    this.stack = new Error().stack || '';
200  }
201
202  if (opt_msg) {
203    this.message = String(opt_msg);
204  }
205  this.name = 'InvalidStateError';
206};
207goog.inherits(ydn.db.InvalidStateError, Error);
208
209
210
211/**
212 * Base class for custom error objects.
213 * @param {*=} opt_msg The message associated with the error.
214 * @constructor
215 * @extends {Error}
216 */
217ydn.db.InvalidAccessError = function(opt_msg) {
218
219  // Ensure there is a stack trace.
220  if (Error.captureStackTrace) {
221    Error.captureStackTrace(this, ydn.db.InvalidAccessError);
222  } else {
223    this.stack = new Error().stack || '';
224  }
225
226  if (opt_msg) {
227    this.message = String(opt_msg);
228  }
229  this.name = 'InvalidAccessError';
230};
231goog.inherits(ydn.db.InvalidAccessError, Error);
232
233
234
235/**
236 * Base class for custom error objects.
237 * @param {*=} opt_msg The message associated with the error.
238 * @constructor
239 * @extends {Error}
240 */
241ydn.db.NotFoundError = function(opt_msg) {
242
243  // Ensure there is a stack trace.
244  if (Error.captureStackTrace) {
245    Error.captureStackTrace(this, ydn.db.NotFoundError);
246  } else {
247    this.stack = new Error().stack || '';
248  }
249
250  if (opt_msg) {
251    this.message = String(opt_msg);
252  }
253  this.name = 'NotFoundError';
254};
255goog.inherits(ydn.db.NotFoundError, Error);
256
257
258/**
259* @type {string} name of error.
260*/
261ydn.db.NotFoundError.prototype.name = 'NotFoundError';
262
263
264if (goog.DEBUG) {
265  /**
266   * @inheritDoc
267   */
268  ydn.db.NotFoundError.prototype.toString = function() {
269    return this.name + ': ' + this.message;
270  };
271}
272
273
274
275/**
276 * Base class for custom error objects.
277 * @param {*=} opt_msg The message associated with the error.
278 * @constructor
279 * @extends {Error}
280 */
281ydn.db.DataCloneError = function(opt_msg) {
282
283  // Ensure there is a stack trace.
284  if (Error.captureStackTrace) {
285    Error.captureStackTrace(this, ydn.db.DataCloneError);
286  } else {
287    this.stack = new Error().stack || '';
288  }
289
290  if (opt_msg) {
291    this.message = String(opt_msg);
292  }
293  this.name = 'DataCloneError';
294};
295goog.inherits(ydn.db.DataCloneError, Error);
296
297
298if (goog.DEBUG) {
299  /**
300   * @inheritDoc
301   */
302  ydn.db.DataCloneError.prototype.toString = function() {
303    return this.name + ': ' + this.message;
304  };
305}
306
307
308
309/**
310 *
311 * @param {SQLError} e original error.
312 * @param {*=} opt_msg optional message.
313 * @constructor
314 * @extends {Error}
315 */
316ydn.db.SQLError = function(e, opt_msg) {
317
318  // Ensure there is a stack trace.
319  if (Error.captureStackTrace) {
320    Error.captureStackTrace(this, ydn.db.SQLError);
321  } else {
322    this.stack = new Error().stack || '';
323  }
324
325  if (opt_msg) {
326    this.message = String(opt_msg);
327  }
328  this.message += ' :' + e.message + ' [' + e.code + ']';
329  this.name = 'SQLError';
330};
331goog.inherits(ydn.db.SQLError, Error);
332
333
334
335if (goog.DEBUG) {
336  /**
337   * @inheritDoc
338   */
339  ydn.db.SQLError.prototype.toString = function() {
340    return this.name + ': ' + this.message;
341  };
342}
343
344
345
346/**
347 *
348 * @param {Error} e original message.
349 * @param {*=} opt_msg optional message.
350 * @constructor
351 * @extends {Error}
352 */
353ydn.db.SecurityError = function(e, opt_msg) {
354
355  // Ensure there is a stack trace.
356  if (Error.captureStackTrace) {
357    Error.captureStackTrace(this, ydn.db.SecurityError);
358  } else {
359    this.stack = new Error().stack || '';
360  }
361
362  if (opt_msg) {
363    this.message = String(opt_msg);
364  }
365  this.message += ' :' + e.message;
366  this.name = 'SecurityError';
367};
368goog.inherits(ydn.db.SecurityError, Error);
369
370
371if (goog.DEBUG) {
372  /**
373   * @inheritDoc
374   */
375  ydn.db.SecurityError.prototype.toString = function() {
376    return this.name + ': ' + this.message;
377  };
378}
379
380
381
382/**
383 *
384 * @param {*=} opt_msg optional message.
385 * @constructor
386 * @extends {Error}
387 */
388ydn.db.SqlParseError = function(opt_msg) {
389
390  // Ensure there is a stack trace.
391  if (Error.captureStackTrace) {
392    Error.captureStackTrace(this, ydn.db.SqlParseError);
393  } else {
394    this.stack = new Error().stack || '';
395  }
396
397  if (opt_msg) {
398    this.message = String(opt_msg);
399  }
400  this.name = 'ydn.db.SqlParseError';
401};
402goog.inherits(ydn.db.SqlParseError, Error);
403
404
405
406/**
407 *
408 * @param {*=} opt_msg optional message.
409 * @constructor
410 * @extends {Error}
411 */
412ydn.db.TimeoutError = function(opt_msg) {
413
414  // Ensure there is a stack trace.
415  if (Error.captureStackTrace) {
416    Error.captureStackTrace(this, ydn.db.TimeoutError);
417  } else {
418    this.stack = new Error().stack || '';
419  }
420
421  if (opt_msg) {
422    this.message = String(opt_msg);
423  }
424  this.name = 'ydn.db.TimeoutError';
425};
426goog.inherits(ydn.db.TimeoutError, Error);
427
428
429
430/**
431 * @param {*} result request result.
432 * @param {*=} opt_msg optional message.
433 * @constructor
434 * @extends {Error}
435 */
436ydn.db.TxError = function(result, opt_msg) {
437
438  // Ensure there is a stack trace.
439  if (Error.captureStackTrace) {
440    Error.captureStackTrace(this, ydn.db.TxError);
441  } else {
442    this.stack = new Error().stack || '';
443  }
444
445  if (opt_msg) {
446    this.message = String(opt_msg);
447  }
448  this.name = 'TxError';
449  this.result = result;
450};
451goog.inherits(ydn.db.TxError, Error);
452
453
454/**
455 * @type {*}
456 */
457ydn.db.TxError.prototype.result;
458
459
460/**
461 * @return {*} request result.
462 */
463ydn.db.TxError.prototype.getResult = function() {
464  return this.result;
465};
466
467
468
469/**
470 *
471 * @param {*} result request result.
472 * @param {*=} opt_msg optional message.
473 * @constructor
474 * @extends {ydn.db.TxError}
475 */
476ydn.db.TxAbortedError = function(result, opt_msg) {
477  goog.base(this, result, opt_msg);
478  this.name = 'TxAbortedError';
479};
480goog.inherits(ydn.db.TxAbortedError, ydn.db.TxError);
481
482
483