You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.3 KiB

4 years ago
  1. 'use strict'
  2. const assert = require('assert')
  3. const util = require('util')
  4. // RedisError
  5. function RedisError (message) {
  6. Object.defineProperty(this, 'message', {
  7. value: message || '',
  8. configurable: true,
  9. writable: true
  10. })
  11. Error.captureStackTrace(this, this.constructor)
  12. }
  13. util.inherits(RedisError, Error)
  14. Object.defineProperty(RedisError.prototype, 'name', {
  15. value: 'RedisError',
  16. configurable: true,
  17. writable: true
  18. })
  19. // ParserError
  20. function ParserError (message, buffer, offset) {
  21. assert(buffer)
  22. assert.strictEqual(typeof offset, 'number')
  23. Object.defineProperty(this, 'message', {
  24. value: message || '',
  25. configurable: true,
  26. writable: true
  27. })
  28. const tmp = Error.stackTraceLimit
  29. Error.stackTraceLimit = 2
  30. Error.captureStackTrace(this, this.constructor)
  31. Error.stackTraceLimit = tmp
  32. this.offset = offset
  33. this.buffer = buffer
  34. }
  35. util.inherits(ParserError, RedisError)
  36. Object.defineProperty(ParserError.prototype, 'name', {
  37. value: 'ParserError',
  38. configurable: true,
  39. writable: true
  40. })
  41. // ReplyError
  42. function ReplyError (message) {
  43. Object.defineProperty(this, 'message', {
  44. value: message || '',
  45. configurable: true,
  46. writable: true
  47. })
  48. const tmp = Error.stackTraceLimit
  49. Error.stackTraceLimit = 2
  50. Error.captureStackTrace(this, this.constructor)
  51. Error.stackTraceLimit = tmp
  52. }
  53. util.inherits(ReplyError, RedisError)
  54. Object.defineProperty(ReplyError.prototype, 'name', {
  55. value: 'ReplyError',
  56. configurable: true,
  57. writable: true
  58. })
  59. // AbortError
  60. function AbortError (message) {
  61. Object.defineProperty(this, 'message', {
  62. value: message || '',
  63. configurable: true,
  64. writable: true
  65. })
  66. Error.captureStackTrace(this, this.constructor)
  67. }
  68. util.inherits(AbortError, RedisError)
  69. Object.defineProperty(AbortError.prototype, 'name', {
  70. value: 'AbortError',
  71. configurable: true,
  72. writable: true
  73. })
  74. // InterruptError
  75. function InterruptError (message) {
  76. Object.defineProperty(this, 'message', {
  77. value: message || '',
  78. configurable: true,
  79. writable: true
  80. })
  81. Error.captureStackTrace(this, this.constructor)
  82. }
  83. util.inherits(InterruptError, AbortError)
  84. Object.defineProperty(InterruptError.prototype, 'name', {
  85. value: 'InterruptError',
  86. configurable: true,
  87. writable: true
  88. })
  89. module.exports = {
  90. RedisError,
  91. ParserError,
  92. ReplyError,
  93. AbortError,
  94. InterruptError
  95. }