PageRenderTime 65ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/closure/goog/db/error.js

https://bitbucket.org/orange_and_bronze/closure-library
JavaScript | 173 lines | 94 code | 17 blank | 62 comment | 2 complexity | 14e6dac1186b2722da28ee74b679cfd4 MD5 | raw file
Possible License(s): Apache-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. };
  82. /**
  83. * Error codes for database errors.
  84. * @see http://www.w3.org/TR/IndexedDB/#idl-def-IDBDatabaseException
  85. *
  86. * @enum {number}
  87. */
  88. goog.db.Error.ErrorCode = {
  89. UNKNOWN_ERR: (goog.global.IDBDatabaseException ||
  90. goog.global.webkitIDBDatabaseException ||
  91. goog.db.Error.DatabaseErrorCode_).UNKNOWN_ERR,
  92. NON_TRANSIENT_ERR: (goog.global.IDBDatabaseException ||
  93. goog.global.webkitIDBDatabaseException ||
  94. goog.db.Error.DatabaseErrorCode_).NON_TRANSIENT_ERR,
  95. NOT_FOUND_ERR: (goog.global.IDBDatabaseException ||
  96. goog.global.webkitIDBDatabaseException ||
  97. goog.db.Error.DatabaseErrorCode_).NOT_FOUND_ERR,
  98. CONSTRAINT_ERR: (goog.global.IDBDatabaseException ||
  99. goog.global.webkitIDBDatabaseException ||
  100. goog.db.Error.DatabaseErrorCode_).CONSTRAINT_ERR,
  101. DATA_ERR: (goog.global.IDBDatabaseException ||
  102. goog.global.webkitIDBDatabaseException ||
  103. goog.db.Error.DatabaseErrorCode_).DATA_ERR,
  104. NOT_ALLOWED_ERR: (goog.global.IDBDatabaseException ||
  105. goog.global.webkitIDBDatabaseException ||
  106. goog.db.Error.DatabaseErrorCode_).NOT_ALLOWED_ERR,
  107. TRANSACTION_INACTIVE_ERR: (goog.global.IDBDatabaseException ||
  108. goog.global.webkitIDBDatabaseException ||
  109. goog.db.Error.DatabaseErrorCode_).TRANSACTION_INACTIVE_ERR,
  110. ABORT_ERR: (goog.global.IDBDatabaseException ||
  111. goog.global.webkitIDBDatabaseException ||
  112. goog.db.Error.DatabaseErrorCode_).ABORT_ERR,
  113. READ_ONLY_ERR: (goog.global.IDBDatabaseException ||
  114. goog.global.webkitIDBDatabaseException ||
  115. goog.db.Error.DatabaseErrorCode_).READ_ONLY_ERR,
  116. TIMEOUT_ERR: (goog.global.IDBDatabaseException ||
  117. goog.global.webkitIDBDatabaseException ||
  118. goog.db.Error.DatabaseErrorCode_).TIMEOUT_ERR,
  119. QUOTA_ERR: (goog.global.IDBDatabaseException ||
  120. goog.global.webkitIDBDatabaseException ||
  121. goog.db.Error.DatabaseErrorCode_).QUOTA_ERR
  122. };
  123. /**
  124. * Translates an error code into a more useful message.
  125. *
  126. * @param {number} code Error code.
  127. * @return {string} A debug message.
  128. */
  129. goog.db.Error.getMessage = function(code) {
  130. switch (code) {
  131. case goog.db.Error.ErrorCode.UNKNOWN_ERR:
  132. return 'Unknown error';
  133. case goog.db.Error.ErrorCode.NON_TRANSIENT_ERR:
  134. return 'Invalid operation';
  135. case goog.db.Error.ErrorCode.NOT_FOUND_ERR:
  136. return 'Required database object not found';
  137. case goog.db.Error.ErrorCode.CONSTRAINT_ERR:
  138. return 'Constraint unsatisfied';
  139. case goog.db.Error.ErrorCode.DATA_ERR:
  140. return 'Invalid data';
  141. case goog.db.Error.ErrorCode.NOT_ALLOWED_ERR:
  142. return 'Operation disallowed';
  143. case goog.db.Error.ErrorCode.TRANSACTION_INACTIVE_ERR:
  144. return 'Transaction not active';
  145. case goog.db.Error.ErrorCode.ABORT_ERR:
  146. return 'Request aborted';
  147. case goog.db.Error.ErrorCode.READ_ONLY_ERR:
  148. return 'Modifying operation not allowed in a read-only transaction';
  149. case goog.db.Error.ErrorCode.TIMEOUT_ERR:
  150. return 'Transaction timed out';
  151. case goog.db.Error.ErrorCode.QUOTA_ERR:
  152. return 'Database storage space quota exceeded';
  153. default:
  154. return 'Unrecognized exception with code ' + code;
  155. }
  156. };