package/package.json000644 001750 001750 0000002056 13113653641013025 0ustar00000000 000000 { "name": "redis-errors", "version": "1.2.0", "description": "Error classes used in node_redis", "main": "index.js", "scripts": { "test": "npm run coverage", "lint": "standard --fix", "posttest": "npm run lint && npm run coverage:check", "coverage": "node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -R spec", "coverage:check": "node ./node_modules/istanbul/lib/cli.js check-coverage --statement 100" }, "repository": { "type": "git", "url": "git+https://github.com/NodeRedis/redis-errors.git" }, "keywords": [ "redis", "javascript", "node", "error" ], "engines": { "node": ">=4" }, "devDependencies": { "istanbul": "^0.4.0", "mocha": "^3.1.2", "standard": "^10.0.0" }, "author": "Ruben Bridgewater", "license": "MIT", "bugs": { "url": "https://github.com/NodeRedis/redis-errors/issues" }, "homepage": "https://github.com/NodeRedis/redis-errors#readme", "directories": { "test": "test", "lib": "lib" } } package/.npmignore000644 001750 001750 0000000232 13113654504012527 0ustar00000000 000000 # IntelliJ project files .idea *.iml out gen # Irrelevant files and folders benchmark coverage test .travis.yml .gitignore *.log .vscode .codeclimate.ymlpackage/README.md000644 001750 001750 0000005542 13111737666012031 0ustar00000000 000000 [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) # redis-errors All error classes used in [node_redis](https://github.com/NodeRedis/node_redis) from v.3.0.0 are in here. They can be required as needed. ## Install Install with [NPM](https://npmjs.org/): npm install redis-errors ## Usage ```js const { ReplyError, InterruptError } = require('redis-errors'); // Using async await try { await client.set('foo') // Missing value } catch (err) { if (err instanceof InterruptError) { console.error('Command might have been processed') } if (err instanceof ReplyError) { // ... } throw err } // Using callbacks client.set('foo', (err, res) => { if (err) { if (err instanceof InterruptError) { // ... } } }) ``` ### Error classes All errors returned by NodeRedis use own Error classes. You can distinguish different errors easily by checking for these classes. To know what caused the error they might contain properties to know in more detail what happened. Each error contains a `message`, a `name` and a `stack` property. Please be aware that the stack might not be useful due to the async nature and is in those cases therefore limited to two frames. There might be more not yet documented properties as well. Please feel free to open a pull request to document those as well. #### RedisError `Properties`: Properties depend on the individual error. All errors returned by NodeRedis (client) are `RedisError`s. Subclass of `Error` #### ReplyError `Properties`: * `args`: The arguments passed to the command. * `command`: The command name. * `code`: The `Redis` error code. Redis itself uses some internal error codes. All errors returned by Redis itself (server) will be a `ReplyError`. Subclass of `RedisError` #### ParserError `Properties`: * `buffer`: The raw buffer input stringified. * `offset`: The character count where the parsing error occurred. Parsing errors are returned as `ParserError`. Subclass of `RedisError` **Note:** If you encounter one of these please report that error including the attached `offset` and `buffer` properties! #### AbortError `Properties`: * `args`: The arguments passed to the command. * `command`: The command name. If a command was not yet executed but rejected, it'll return a `AbortError`. Subclass of `RedisError` #### InterruptError `Properties`: * `args`: The arguments passed to the command. * `command`: The command name. * `origin`: The original error that caused the interrupt All executed commands that could not fulfill (e.g. network drop while executing) return a `InterruptError`. Subclass of `AbortError` **Note:** Interrupt errors can happen for multiple reasons that are out of the scope of NodeRedis itself. There is nothing that can be done on library side to prevent those. ## License [MIT](./LICENSE) package/LICENSE000664 001750 001750 0000002075 13107436310011542 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2017 Ruben Bridgewater Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/index.js000644 001750 001750 0000000305 13113653305012174 0ustar00000000 000000 'use strict' const Errors = process.version.charCodeAt(1) < 55 && process.version.charCodeAt(2) === 46 ? require('./lib/old') // Node.js < 7 : require('./lib/modern') module.exports = Errors package/lib/modern.js000644 001750 001750 0000002026 13113640053013115 0ustar00000000 000000 'use strict' const assert = require('assert') class RedisError extends Error { get name () { return this.constructor.name } } class ParserError extends RedisError { constructor (message, buffer, offset) { assert(buffer) assert.strictEqual(typeof offset, 'number') const tmp = Error.stackTraceLimit Error.stackTraceLimit = 2 super(message) Error.stackTraceLimit = tmp this.offset = offset this.buffer = buffer } get name () { return this.constructor.name } } class ReplyError extends RedisError { constructor (message) { const tmp = Error.stackTraceLimit Error.stackTraceLimit = 2 super(message) Error.stackTraceLimit = tmp } get name () { return this.constructor.name } } class AbortError extends RedisError { get name () { return this.constructor.name } } class InterruptError extends AbortError { get name () { return this.constructor.name } } module.exports = { RedisError, ParserError, ReplyError, AbortError, InterruptError } package/lib/old.js000644 001750 001750 0000004523 13113657061012422 0ustar00000000 000000 'use strict' const assert = require('assert') const util = require('util') // RedisError function RedisError (message) { Object.defineProperty(this, 'message', { value: message || '', configurable: true, writable: true }) Error.captureStackTrace(this, this.constructor) } util.inherits(RedisError, Error) Object.defineProperty(RedisError.prototype, 'name', { value: 'RedisError', configurable: true, writable: true }) // ParserError function ParserError (message, buffer, offset) { assert(buffer) assert.strictEqual(typeof offset, 'number') Object.defineProperty(this, 'message', { value: message || '', configurable: true, writable: true }) const tmp = Error.stackTraceLimit Error.stackTraceLimit = 2 Error.captureStackTrace(this, this.constructor) Error.stackTraceLimit = tmp this.offset = offset this.buffer = buffer } util.inherits(ParserError, RedisError) Object.defineProperty(ParserError.prototype, 'name', { value: 'ParserError', configurable: true, writable: true }) // ReplyError function ReplyError (message) { Object.defineProperty(this, 'message', { value: message || '', configurable: true, writable: true }) const tmp = Error.stackTraceLimit Error.stackTraceLimit = 2 Error.captureStackTrace(this, this.constructor) Error.stackTraceLimit = tmp } util.inherits(ReplyError, RedisError) Object.defineProperty(ReplyError.prototype, 'name', { value: 'ReplyError', configurable: true, writable: true }) // AbortError function AbortError (message) { Object.defineProperty(this, 'message', { value: message || '', configurable: true, writable: true }) Error.captureStackTrace(this, this.constructor) } util.inherits(AbortError, RedisError) Object.defineProperty(AbortError.prototype, 'name', { value: 'AbortError', configurable: true, writable: true }) // InterruptError function InterruptError (message) { Object.defineProperty(this, 'message', { value: message || '', configurable: true, writable: true }) Error.captureStackTrace(this, this.constructor) } util.inherits(InterruptError, AbortError) Object.defineProperty(InterruptError.prototype, 'name', { value: 'InterruptError', configurable: true, writable: true }) module.exports = { RedisError, ParserError, ReplyError, AbortError, InterruptError }