PageRenderTime 57ms CodeModel.GetById 30ms 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
Possible License(s): Apache-2.0
  1. /**
  2. *
  3. * @fileoverview Error classes for the database module.
  4. *
  5. */
  6. goog.provide('ydn.db.ConstraintError');
  7. goog.provide('ydn.db.InternalError');
  8. goog.provide('ydn.db.InvalidKeyException');
  9. goog.provide('ydn.db.InvalidStateError');
  10. goog.provide('ydn.db.NotFoundError');
  11. goog.provide('ydn.db.ScopeError');
  12. goog.provide('ydn.db.SecurityError');
  13. goog.provide('ydn.db.TimeoutError');
  14. goog.provide('ydn.db.VersionError');
  15. /**
  16. * Base class for custom error objects.
  17. * @param {*=} opt_msg The message associated with the error.
  18. * @constructor
  19. * @extends {Error}
  20. */
  21. ydn.db.ConstraintError = function(opt_msg) {
  22. // Ensure there is a stack trace.
  23. if (Error.captureStackTrace) {
  24. Error.captureStackTrace(this, ydn.db.ConstraintError);
  25. } else {
  26. this.stack = new Error().stack || '';
  27. }
  28. if (opt_msg) {
  29. this.message = String(opt_msg);
  30. }
  31. this.name = 'ConstraintError';
  32. };
  33. goog.inherits(ydn.db.ConstraintError, Error);
  34. /**
  35. *
  36. * @type {string}
  37. */
  38. ydn.db.ConstraintError.prototype.name = 'ConstraintError';
  39. if (goog.DEBUG) {
  40. /**
  41. * @inheritDoc
  42. */
  43. ydn.db.ConstraintError.prototype.toString = function() {
  44. return this.name + ': ' + this.message;
  45. };
  46. }
  47. /**
  48. * Base class for custom error objects.
  49. * @param {*=} opt_msg The message associated with the error.
  50. * @constructor
  51. * @extends {Error}
  52. */
  53. ydn.db.InvalidKeyException = function(opt_msg) {
  54. // Ensure there is a stack trace.
  55. if (Error.captureStackTrace) {
  56. Error.captureStackTrace(this, ydn.db.InvalidKeyException);
  57. } else {
  58. this.stack = new Error().stack || '';
  59. }
  60. if (opt_msg) {
  61. this.message = String(opt_msg);
  62. }
  63. this.name = 'ydn.db.InvalidKeyException';
  64. };
  65. goog.inherits(ydn.db.InvalidKeyException, Error);
  66. if (goog.DEBUG) {
  67. /**
  68. * @inheritDoc
  69. */
  70. ydn.db.InvalidKeyException.prototype.toString = function() {
  71. return this.name + ': ' + this.message;
  72. };
  73. }
  74. /**
  75. * Base class for custom error objects.
  76. * @param {*=} opt_msg The message associated with the error.
  77. * @constructor
  78. * @extends {Error}
  79. */
  80. ydn.db.VersionError = function(opt_msg) {
  81. // Ensure there is a stack trace.
  82. if (Error.captureStackTrace) {
  83. Error.captureStackTrace(this, ydn.db.VersionError);
  84. } else {
  85. this.stack = new Error().stack || '';
  86. }
  87. if (opt_msg) {
  88. this.message = String(opt_msg);
  89. }
  90. this.name = 'ydn.db.VersionError';
  91. };
  92. goog.inherits(ydn.db.VersionError, Error);
  93. /**
  94. * @type {string} name of error.
  95. */
  96. ydn.db.VersionError.prototype.name = 'ydn.db.VersionError';
  97. if (goog.DEBUG) {
  98. /**
  99. * @inheritDoc
  100. */
  101. ydn.db.VersionError.prototype.toString = function() {
  102. return this.name + ': ' + this.message;
  103. };
  104. }
  105. /**
  106. * Base class for custom error objects.
  107. * @param {*=} opt_msg The message associated with the error.
  108. * @constructor
  109. * @extends {Error}
  110. */
  111. ydn.db.InternalError = function(opt_msg) {
  112. // Ensure there is a stack trace.
  113. if (Error.captureStackTrace) {
  114. Error.captureStackTrace(this, ydn.db.InternalError);
  115. } else {
  116. this.stack = new Error().stack || '';
  117. }
  118. if (opt_msg) {
  119. this.message = String(opt_msg);
  120. }
  121. };
  122. goog.inherits(ydn.db.InternalError, Error);
  123. /**
  124. * @type {string} name of error.
  125. */
  126. ydn.db.InternalError.prototype.name = 'ydn.db.InternalError';
  127. /**
  128. * Base class for custom error objects.
  129. * @param {*=} opt_msg The message associated with the error.
  130. * @constructor
  131. * @extends {Error}
  132. */
  133. ydn.db.ScopeError = function(opt_msg) {
  134. // Ensure there is a stack trace.
  135. if (Error.captureStackTrace) {
  136. Error.captureStackTrace(this, ydn.db.ScopeError);
  137. } else {
  138. this.stack = new Error().stack || '';
  139. }
  140. if (opt_msg) {
  141. this.message = String(opt_msg);
  142. }
  143. this.name = 'ydn.db.ScopeError';
  144. };
  145. goog.inherits(ydn.db.ScopeError, Error);
  146. /**
  147. * Base class for custom error objects.
  148. * @param {*=} opt_msg The message associated with the error.
  149. * @constructor
  150. * @extends {Error}
  151. */
  152. ydn.db.InvalidStateError = function(opt_msg) {
  153. // Ensure there is a stack trace.
  154. if (Error.captureStackTrace) {
  155. Error.captureStackTrace(this, ydn.db.InvalidStateError);
  156. } else {
  157. this.stack = new Error().stack || '';
  158. }
  159. if (opt_msg) {
  160. this.message = String(opt_msg);
  161. }
  162. this.name = 'InvalidStateError';
  163. };
  164. goog.inherits(ydn.db.InvalidStateError, Error);
  165. /**
  166. * Base class for custom error objects.
  167. * @param {*=} opt_msg The message associated with the error.
  168. * @constructor
  169. * @extends {Error}
  170. */
  171. ydn.db.InvalidAccessError = function(opt_msg) {
  172. // Ensure there is a stack trace.
  173. if (Error.captureStackTrace) {
  174. Error.captureStackTrace(this, ydn.db.InvalidAccessError);
  175. } else {
  176. this.stack = new Error().stack || '';
  177. }
  178. if (opt_msg) {
  179. this.message = String(opt_msg);
  180. }
  181. this.name = 'InvalidAccessError';
  182. };
  183. goog.inherits(ydn.db.InvalidAccessError, Error);
  184. /**
  185. * Base class for custom error objects.
  186. * @param {*=} opt_msg The message associated with the error.
  187. * @constructor
  188. * @extends {Error}
  189. */
  190. ydn.db.NotFoundError = function(opt_msg) {
  191. // Ensure there is a stack trace.
  192. if (Error.captureStackTrace) {
  193. Error.captureStackTrace(this, ydn.db.NotFoundError);
  194. } else {
  195. this.stack = new Error().stack || '';
  196. }
  197. if (opt_msg) {
  198. this.message = String(opt_msg);
  199. }
  200. this.name = 'NotFoundError';
  201. };
  202. goog.inherits(ydn.db.NotFoundError, Error);
  203. /**
  204. * @type {string} name of error.
  205. */
  206. ydn.db.NotFoundError.prototype.name = 'NotFoundError';
  207. if (goog.DEBUG) {
  208. /**
  209. * @inheritDoc
  210. */
  211. ydn.db.NotFoundError.prototype.toString = function() {
  212. return this.name + ': ' + this.message;
  213. };
  214. }
  215. /**
  216. * Base class for custom error objects.
  217. * @param {*=} opt_msg The message associated with the error.
  218. * @constructor
  219. * @extends {Error}
  220. */
  221. ydn.db.DataCloneError = function(opt_msg) {
  222. // Ensure there is a stack trace.
  223. if (Error.captureStackTrace) {
  224. Error.captureStackTrace(this, ydn.db.DataCloneError);
  225. } else {
  226. this.stack = new Error().stack || '';
  227. }
  228. if (opt_msg) {
  229. this.message = String(opt_msg);
  230. }
  231. this.name = 'DataCloneError';
  232. };
  233. goog.inherits(ydn.db.DataCloneError, Error);
  234. if (goog.DEBUG) {
  235. /**
  236. * @inheritDoc
  237. */
  238. ydn.db.DataCloneError.prototype.toString = function() {
  239. return this.name + ': ' + this.message;
  240. };
  241. }
  242. /**
  243. *
  244. * @param {SQLError} e original error.
  245. * @param {*=} opt_msg optional message.
  246. * @constructor
  247. * @extends {Error}
  248. */
  249. ydn.db.SQLError = function(e, opt_msg) {
  250. // Ensure there is a stack trace.
  251. if (Error.captureStackTrace) {
  252. Error.captureStackTrace(this, ydn.db.SQLError);
  253. } else {
  254. this.stack = new Error().stack || '';
  255. }
  256. if (opt_msg) {
  257. this.message = String(opt_msg);
  258. }
  259. this.message += ' :' + e.message + ' [' + e.code + ']';
  260. this.name = 'SQLError';
  261. };
  262. goog.inherits(ydn.db.SQLError, Error);
  263. if (goog.DEBUG) {
  264. /**
  265. * @inheritDoc
  266. */
  267. ydn.db.SQLError.prototype.toString = function() {
  268. return this.name + ': ' + this.message;
  269. };
  270. }
  271. /**
  272. *
  273. * @param {Error} e original message.
  274. * @param {*=} opt_msg optional message.
  275. * @constructor
  276. * @extends {Error}
  277. */
  278. ydn.db.SecurityError = function(e, opt_msg) {
  279. // Ensure there is a stack trace.
  280. if (Error.captureStackTrace) {
  281. Error.captureStackTrace(this, ydn.db.SecurityError);
  282. } else {
  283. this.stack = new Error().stack || '';
  284. }
  285. if (opt_msg) {
  286. this.message = String(opt_msg);
  287. }
  288. this.message += ' :' + e.message;
  289. this.name = 'SecurityError';
  290. };
  291. goog.inherits(ydn.db.SecurityError, Error);
  292. if (goog.DEBUG) {
  293. /**
  294. * @inheritDoc
  295. */
  296. ydn.db.SecurityError.prototype.toString = function() {
  297. return this.name + ': ' + this.message;
  298. };
  299. }
  300. /**
  301. *
  302. * @param {*=} opt_msg optional message.
  303. * @constructor
  304. * @extends {Error}
  305. */
  306. ydn.db.SqlParseError = function(opt_msg) {
  307. // Ensure there is a stack trace.
  308. if (Error.captureStackTrace) {
  309. Error.captureStackTrace(this, ydn.db.SqlParseError);
  310. } else {
  311. this.stack = new Error().stack || '';
  312. }
  313. if (opt_msg) {
  314. this.message = String(opt_msg);
  315. }
  316. this.name = 'ydn.db.SqlParseError';
  317. };
  318. goog.inherits(ydn.db.SqlParseError, Error);
  319. /**
  320. *
  321. * @param {*=} opt_msg optional message.
  322. * @constructor
  323. * @extends {Error}
  324. */
  325. ydn.db.TimeoutError = function(opt_msg) {
  326. // Ensure there is a stack trace.
  327. if (Error.captureStackTrace) {
  328. Error.captureStackTrace(this, ydn.db.TimeoutError);
  329. } else {
  330. this.stack = new Error().stack || '';
  331. }
  332. if (opt_msg) {
  333. this.message = String(opt_msg);
  334. }
  335. this.name = 'ydn.db.TimeoutError';
  336. };
  337. goog.inherits(ydn.db.TimeoutError, Error);
  338. /**
  339. * @param {*} result request result.
  340. * @param {*=} opt_msg optional message.
  341. * @constructor
  342. * @extends {Error}
  343. */
  344. ydn.db.TxError = function(result, opt_msg) {
  345. // Ensure there is a stack trace.
  346. if (Error.captureStackTrace) {
  347. Error.captureStackTrace(this, ydn.db.TxError);
  348. } else {
  349. this.stack = new Error().stack || '';
  350. }
  351. if (opt_msg) {
  352. this.message = String(opt_msg);
  353. }
  354. this.name = 'TxError';
  355. this.result = result;
  356. };
  357. goog.inherits(ydn.db.TxError, Error);
  358. /**
  359. * @type {*}
  360. */
  361. ydn.db.TxError.prototype.result;
  362. /**
  363. * @return {*} request result.
  364. */
  365. ydn.db.TxError.prototype.getResult = function() {
  366. return this.result;
  367. };
  368. /**
  369. *
  370. * @param {*} result request result.
  371. * @param {*=} opt_msg optional message.
  372. * @constructor
  373. * @extends {ydn.db.TxError}
  374. */
  375. ydn.db.TxAbortedError = function(result, opt_msg) {
  376. goog.base(this, result, opt_msg);
  377. this.name = 'TxAbortedError';
  378. };
  379. goog.inherits(ydn.db.TxAbortedError, ydn.db.TxError);