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.

116 lines
2.8 KiB

4 years ago
  1. [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
  2. # redis-errors
  3. All error classes used in [node_redis](https://github.com/NodeRedis/node_redis)
  4. from v.3.0.0 are in here. They can be required as needed.
  5. ## Install
  6. Install with [NPM](https://npmjs.org/):
  7. npm install redis-errors
  8. ## Usage
  9. ```js
  10. const { ReplyError, InterruptError } = require('redis-errors');
  11. // Using async await
  12. try {
  13. await client.set('foo') // Missing value
  14. } catch (err) {
  15. if (err instanceof InterruptError) {
  16. console.error('Command might have been processed')
  17. }
  18. if (err instanceof ReplyError) {
  19. // ...
  20. }
  21. throw err
  22. }
  23. // Using callbacks
  24. client.set('foo', (err, res) => {
  25. if (err) {
  26. if (err instanceof InterruptError) {
  27. // ...
  28. }
  29. }
  30. })
  31. ```
  32. ### Error classes
  33. All errors returned by NodeRedis use own Error classes. You can distinguish
  34. different errors easily by checking for these classes.
  35. To know what caused the error they might contain properties to know in more
  36. detail what happened.
  37. Each error contains a `message`, a `name` and a `stack` property. Please be aware
  38. that the stack might not be useful due to the async nature and is in those cases
  39. therefore limited to two frames.
  40. There might be more not yet documented properties as well. Please feel free to
  41. open a pull request to document those as well.
  42. #### RedisError
  43. `Properties`:
  44. Properties depend on the individual error.
  45. All errors returned by NodeRedis (client) are `RedisError`s.
  46. Subclass of `Error`
  47. #### ReplyError
  48. `Properties`:
  49. * `args`: The arguments passed to the command.
  50. * `command`: The command name.
  51. * `code`: The `Redis` error code. Redis itself uses some internal error codes.
  52. All errors returned by Redis itself (server) will be a `ReplyError`.
  53. Subclass of `RedisError`
  54. #### ParserError
  55. `Properties`:
  56. * `buffer`: The raw buffer input stringified.
  57. * `offset`: The character count where the parsing error occurred.
  58. Parsing errors are returned as `ParserError`.
  59. Subclass of `RedisError`
  60. **Note:** If you encounter one of these please report that error including the
  61. attached `offset` and `buffer` properties!
  62. #### AbortError
  63. `Properties`:
  64. * `args`: The arguments passed to the command.
  65. * `command`: The command name.
  66. If a command was not yet executed but rejected, it'll return a `AbortError`.
  67. Subclass of `RedisError`
  68. #### InterruptError
  69. `Properties`:
  70. * `args`: The arguments passed to the command.
  71. * `command`: The command name.
  72. * `origin`: The original error that caused the interrupt
  73. All executed commands that could not fulfill (e.g. network drop while
  74. executing) return a `InterruptError`.
  75. Subclass of `AbortError`
  76. **Note:** Interrupt errors can happen for multiple reasons that are out of the
  77. scope of NodeRedis itself. There is nothing that can be done on library side
  78. to prevent those.
  79. ## License
  80. [MIT](./LICENSE)