PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms 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
  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/**
 16 * @fileoverview Error classes for the IndexedDB wrapper.
 17 *
 18 */
 19
 20
 21goog.provide('goog.db.Error');
 22goog.provide('goog.db.Error.ErrorCode');
 23goog.provide('goog.db.Error.VersionChangeBlockedError');
 24
 25goog.require('goog.debug.Error');
 26
 27
 28
 29/**
 30 * A database error. Since the stack trace can be unhelpful in an asynchronous
 31 * context, the error provides a message about where it was produced.
 32 *
 33 * @param {number} code The error code.
 34 * @param {string} context A description of where the error occured.
 35 * @param {string=} opt_message Additional message.
 36 * @constructor
 37 * @extends {goog.debug.Error}
 38 */
 39goog.db.Error = function(code, context, opt_message) {
 40  var msg = 'Error ' + context + ': ' + goog.db.Error.getMessage(code);
 41  if (opt_message) {
 42    msg += ', ' + opt_message;
 43  }
 44  goog.base(this, msg);
 45
 46  /**
 47   * The code for this error.
 48   *
 49   * @type {number}
 50   */
 51  this.code = code;
 52};
 53goog.inherits(goog.db.Error, goog.debug.Error);
 54
 55
 56
 57/**
 58 * A specific kind of database error. If a Version Change is unable to proceed
 59 * due to other open database connections, it will block and this error will be
 60 * thrown.
 61 *
 62 * @constructor
 63 * @extends {goog.debug.Error}
 64 */
 65goog.db.Error.VersionChangeBlockedError = function() {
 66  goog.base(this, 'Version change blocked');
 67};
 68goog.inherits(goog.db.Error.VersionChangeBlockedError, goog.debug.Error);
 69
 70
 71/**
 72 * Synthetic error codes for database errors, for use when IndexedDB
 73 * support is not available. This numbering differs in practice
 74 * from the browser implementations, but it is not meant to be reliable:
 75 * this object merely ensures that goog.db.Error is loadable on platforms
 76 * that do not support IndexedDB.
 77 *
 78 * @enum {number}
 79 * @private
 80 */
 81goog.db.Error.DatabaseErrorCode_ = {
 82  UNKNOWN_ERR: 1,
 83  NON_TRANSIENT_ERR: 2,
 84  NOT_FOUND_ERR: 3,
 85  CONSTRAINT_ERR: 4,
 86  DATA_ERR: 5,
 87  NOT_ALLOWED_ERR: 6,
 88  TRANSACTION_INACTIVE_ERR: 7,
 89  ABORT_ERR: 8,
 90  READ_ONLY_ERR: 9,
 91  TRANSIENT_ERR: 11,
 92  TIMEOUT_ERR: 10,
 93  QUOTA_ERR: 11,
 94  INVALID_ACCESS_ERR: 12
 95};
 96
 97
 98/**
 99 * Error codes for database errors.
100 * @see http://www.w3.org/TR/IndexedDB/#idl-def-IDBDatabaseException
101 *
102 * @enum {number}
103 */
104goog.db.Error.ErrorCode = {
105  UNKNOWN_ERR: (goog.global.IDBDatabaseException ||
106      goog.global.webkitIDBDatabaseException ||
107      goog.db.Error.DatabaseErrorCode_).UNKNOWN_ERR,
108  NON_TRANSIENT_ERR: (goog.global.IDBDatabaseException ||
109      goog.global.webkitIDBDatabaseException ||
110      goog.db.Error.DatabaseErrorCode_).NON_TRANSIENT_ERR,
111  NOT_FOUND_ERR: (goog.global.IDBDatabaseException ||
112      goog.global.webkitIDBDatabaseException ||
113      goog.db.Error.DatabaseErrorCode_).NOT_FOUND_ERR,
114  CONSTRAINT_ERR: (goog.global.IDBDatabaseException ||
115      goog.global.webkitIDBDatabaseException ||
116      goog.db.Error.DatabaseErrorCode_).CONSTRAINT_ERR,
117  DATA_ERR: (goog.global.IDBDatabaseException ||
118      goog.global.webkitIDBDatabaseException ||
119      goog.db.Error.DatabaseErrorCode_).DATA_ERR,
120  NOT_ALLOWED_ERR: (goog.global.IDBDatabaseException ||
121      goog.global.webkitIDBDatabaseException ||
122      goog.db.Error.DatabaseErrorCode_).NOT_ALLOWED_ERR,
123  TRANSACTION_INACTIVE_ERR: (goog.global.IDBDatabaseException ||
124      goog.global.webkitIDBDatabaseException ||
125      goog.db.Error.DatabaseErrorCode_).TRANSACTION_INACTIVE_ERR,
126  ABORT_ERR: (goog.global.IDBDatabaseException ||
127      goog.global.webkitIDBDatabaseException ||
128      goog.db.Error.DatabaseErrorCode_).ABORT_ERR,
129  READ_ONLY_ERR: (goog.global.IDBDatabaseException ||
130      goog.global.webkitIDBDatabaseException ||
131      goog.db.Error.DatabaseErrorCode_).READ_ONLY_ERR,
132  TIMEOUT_ERR: (goog.global.IDBDatabaseException ||
133      goog.global.webkitIDBDatabaseException ||
134      goog.db.Error.DatabaseErrorCode_).TIMEOUT_ERR,
135  QUOTA_ERR: (goog.global.IDBDatabaseException ||
136      goog.global.webkitIDBDatabaseException ||
137      goog.db.Error.DatabaseErrorCode_).QUOTA_ERR,
138  INVALID_ACCESS_ERR: (goog.global.DOMException ||
139      goog.db.Error.DatabaseErrorCode_).INVALID_ACCESS_ERR
140};
141
142
143/**
144 * Translates an error code into a more useful message.
145 *
146 * @param {number} code Error code.
147 * @return {string} A debug message.
148 */
149goog.db.Error.getMessage = function(code) {
150  switch (code) {
151    case goog.db.Error.ErrorCode.UNKNOWN_ERR:
152      return 'Unknown error';
153    case goog.db.Error.ErrorCode.NON_TRANSIENT_ERR:
154      return 'Invalid operation';
155    case goog.db.Error.ErrorCode.NOT_FOUND_ERR:
156      return 'Required database object not found';
157    case goog.db.Error.ErrorCode.CONSTRAINT_ERR:
158      return 'Constraint unsatisfied';
159    case goog.db.Error.ErrorCode.DATA_ERR:
160      return 'Invalid data';
161    case goog.db.Error.ErrorCode.NOT_ALLOWED_ERR:
162      return 'Operation disallowed';
163    case goog.db.Error.ErrorCode.TRANSACTION_INACTIVE_ERR:
164      return 'Transaction not active';
165    case goog.db.Error.ErrorCode.ABORT_ERR:
166      return 'Request aborted';
167    case goog.db.Error.ErrorCode.READ_ONLY_ERR:
168      return 'Modifying operation not allowed in a read-only transaction';
169    case goog.db.Error.ErrorCode.TIMEOUT_ERR:
170      return 'Transaction timed out';
171    case goog.db.Error.ErrorCode.QUOTA_ERR:
172      return 'Database storage space quota exceeded';
173    case goog.db.Error.ErrorCode.INVALID_ACCESS_ERR:
174      return 'Invalid operation';
175    default:
176      return 'Unrecognized exception with code ' + code;
177  }
178};