PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/closure/goog/db/error.js

https://bitbucket.org/abahdanovich/selenium
JavaScript | 178 lines | 99 code | 17 blank | 62 comment | 2 complexity | 57e8acb2df6c5464564d4f4979023fc7 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, AGPL-1.0, MIT, Apache-2.0, BSD-3-Clause, GPL-2.0
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Error classes for the IndexedDB wrapper.
  16. *
  17. */
  18. goog.provide('goog.db.Error');
  19. goog.provide('goog.db.Error.ErrorCode');
  20. goog.provide('goog.db.Error.VersionChangeBlockedError');
  21. goog.require('goog.debug.Error');
  22. /**
  23. * A database error. Since the stack trace can be unhelpful in an asynchronous
  24. * context, the error provides a message about where it was produced.
  25. *
  26. * @param {number} code The error code.
  27. * @param {string} context A description of where the error occured.
  28. * @param {string=} opt_message Additional message.
  29. * @constructor
  30. * @extends {goog.debug.Error}
  31. */
  32. goog.db.Error = function(code, context, opt_message) {
  33. var msg = 'Error ' + context + ': ' + goog.db.Error.getMessage(code);
  34. if (opt_message) {
  35. msg += ', ' + opt_message;
  36. }
  37. goog.base(this, msg);
  38. /**
  39. * The code for this error.
  40. *
  41. * @type {number}
  42. */
  43. this.code = code;
  44. };
  45. goog.inherits(goog.db.Error, goog.debug.Error);
  46. /**
  47. * A specific kind of database error. If a Version Change is unable to proceed
  48. * due to other open database connections, it will block and this error will be
  49. * thrown.
  50. *
  51. * @constructor
  52. * @extends {goog.debug.Error}
  53. */
  54. goog.db.Error.VersionChangeBlockedError = function() {
  55. goog.base(this, 'Version change blocked');
  56. };
  57. goog.inherits(goog.db.Error.VersionChangeBlockedError, goog.debug.Error);
  58. /**
  59. * Synthetic error codes for database errors, for use when IndexedDB
  60. * support is not available. This numbering differs in practice
  61. * from the browser implementations, but it is not meant to be reliable:
  62. * this object merely ensures that goog.db.Error is loadable on platforms
  63. * that do not support IndexedDB.
  64. *
  65. * @enum {number}
  66. * @private
  67. */
  68. goog.db.Error.DatabaseErrorCode_ = {
  69. UNKNOWN_ERR: 1,
  70. NON_TRANSIENT_ERR: 2,
  71. NOT_FOUND_ERR: 3,
  72. CONSTRAINT_ERR: 4,
  73. DATA_ERR: 5,
  74. NOT_ALLOWED_ERR: 6,
  75. TRANSACTION_INACTIVE_ERR: 7,
  76. ABORT_ERR: 8,
  77. READ_ONLY_ERR: 9,
  78. TRANSIENT_ERR: 11,
  79. TIMEOUT_ERR: 10,
  80. QUOTA_ERR: 11,
  81. INVALID_ACCESS_ERR: 12
  82. };
  83. /**
  84. * Error codes for database errors.
  85. * @see http://www.w3.org/TR/IndexedDB/#idl-def-IDBDatabaseException
  86. *
  87. * @enum {number}
  88. */
  89. goog.db.Error.ErrorCode = {
  90. UNKNOWN_ERR: (goog.global.IDBDatabaseException ||
  91. goog.global.webkitIDBDatabaseException ||
  92. goog.db.Error.DatabaseErrorCode_).UNKNOWN_ERR,
  93. NON_TRANSIENT_ERR: (goog.global.IDBDatabaseException ||
  94. goog.global.webkitIDBDatabaseException ||
  95. goog.db.Error.DatabaseErrorCode_).NON_TRANSIENT_ERR,
  96. NOT_FOUND_ERR: (goog.global.IDBDatabaseException ||
  97. goog.global.webkitIDBDatabaseException ||
  98. goog.db.Error.DatabaseErrorCode_).NOT_FOUND_ERR,
  99. CONSTRAINT_ERR: (goog.global.IDBDatabaseException ||
  100. goog.global.webkitIDBDatabaseException ||
  101. goog.db.Error.DatabaseErrorCode_).CONSTRAINT_ERR,
  102. DATA_ERR: (goog.global.IDBDatabaseException ||
  103. goog.global.webkitIDBDatabaseException ||
  104. goog.db.Error.DatabaseErrorCode_).DATA_ERR,
  105. NOT_ALLOWED_ERR: (goog.global.IDBDatabaseException ||
  106. goog.global.webkitIDBDatabaseException ||
  107. goog.db.Error.DatabaseErrorCode_).NOT_ALLOWED_ERR,
  108. TRANSACTION_INACTIVE_ERR: (goog.global.IDBDatabaseException ||
  109. goog.global.webkitIDBDatabaseException ||
  110. goog.db.Error.DatabaseErrorCode_).TRANSACTION_INACTIVE_ERR,
  111. ABORT_ERR: (goog.global.IDBDatabaseException ||
  112. goog.global.webkitIDBDatabaseException ||
  113. goog.db.Error.DatabaseErrorCode_).ABORT_ERR,
  114. READ_ONLY_ERR: (goog.global.IDBDatabaseException ||
  115. goog.global.webkitIDBDatabaseException ||
  116. goog.db.Error.DatabaseErrorCode_).READ_ONLY_ERR,
  117. TIMEOUT_ERR: (goog.global.IDBDatabaseException ||
  118. goog.global.webkitIDBDatabaseException ||
  119. goog.db.Error.DatabaseErrorCode_).TIMEOUT_ERR,
  120. QUOTA_ERR: (goog.global.IDBDatabaseException ||
  121. goog.global.webkitIDBDatabaseException ||
  122. goog.db.Error.DatabaseErrorCode_).QUOTA_ERR,
  123. INVALID_ACCESS_ERR: (goog.global.DOMException ||
  124. goog.db.Error.DatabaseErrorCode_).INVALID_ACCESS_ERR
  125. };
  126. /**
  127. * Translates an error code into a more useful message.
  128. *
  129. * @param {number} code Error code.
  130. * @return {string} A debug message.
  131. */
  132. goog.db.Error.getMessage = function(code) {
  133. switch (code) {
  134. case goog.db.Error.ErrorCode.UNKNOWN_ERR:
  135. return 'Unknown error';
  136. case goog.db.Error.ErrorCode.NON_TRANSIENT_ERR:
  137. return 'Invalid operation';
  138. case goog.db.Error.ErrorCode.NOT_FOUND_ERR:
  139. return 'Required database object not found';
  140. case goog.db.Error.ErrorCode.CONSTRAINT_ERR:
  141. return 'Constraint unsatisfied';
  142. case goog.db.Error.ErrorCode.DATA_ERR:
  143. return 'Invalid data';
  144. case goog.db.Error.ErrorCode.NOT_ALLOWED_ERR:
  145. return 'Operation disallowed';
  146. case goog.db.Error.ErrorCode.TRANSACTION_INACTIVE_ERR:
  147. return 'Transaction not active';
  148. case goog.db.Error.ErrorCode.ABORT_ERR:
  149. return 'Request aborted';
  150. case goog.db.Error.ErrorCode.READ_ONLY_ERR:
  151. return 'Modifying operation not allowed in a read-only transaction';
  152. case goog.db.Error.ErrorCode.TIMEOUT_ERR:
  153. return 'Transaction timed out';
  154. case goog.db.Error.ErrorCode.QUOTA_ERR:
  155. return 'Database storage space quota exceeded';
  156. case goog.db.Error.ErrorCode.INVALID_ACCESS_ERR:
  157. return 'Invalid operation';
  158. default:
  159. return 'Unrecognized exception with code ' + code;
  160. }
  161. };