How to use the redis-errors.ParserError function in redis-errors

To help you get started, we’ve selected a few redis-errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NodeRedis / node-redis-parser / test / parsers.spec.js View on Github external
'use strict'

/* eslint-env mocha */
/* eslint-disable no-new */
/* global BigInt */

const assert = require('assert')
const util = require('util')
const Buffer = require('buffer').Buffer
const Parser = require('..')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
const RedisError = errors.RedisError
const hasBigIntSupport = !/^v[0-9]\./.test(process.version)

// Mock the not needed return functions
function returnReply (data) { console.log(data); throw new Error('failed') }
function returnError (err) { console.log(err); throw new Error('failed') }
function pushReply (data) { console.log(data); throw new Error('failed') }
function returnFatalError (err) { console.log(JSON.stringify(err.buffer.slice(err.offset).toString())); throw err }

function getBigInt (input, sign) {
  if (hasBigIntSupport) {
    return input === '-' ? -BigInt(sign) : BigInt(input)
  }
  return input === '-' ? input + sign : ('' + input)
}
github NodeRedis / node-redis-parser / test / parsers.spec.js View on Github external
'use strict'

/* eslint-env mocha */
/* eslint-disable no-new */

const assert = require('assert')
const util = require('util')
const Buffer = require('buffer').Buffer
const JavascriptParser = require('../')
const HiredisParser = require('./hiredis')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
const RedisError = errors.RedisError
const parsers = [HiredisParser, JavascriptParser]

// Mock the not needed return functions
function returnReply () { throw new Error('failed') }
function returnError () { throw new Error('failed') }
function returnFatalError (err) { throw err }

describe('parsers', function () {
  describe('general parser functionality', function () {
    it('fail for missing options argument', function () {
      assert.throws(function () {
        new JavascriptParser()
      }, function (err) {
        assert(err instanceof TypeError)
        return true
github NodeRedis / node-redis-parser / test / hiredis.js View on Github external
'use strict'

const hiredis = require('hiredis')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError

/**
 * Parse data
 * @param parser
 * @returns {*}
 */
function parseData (parser, data) {
  try {
    return parser.reader.get()
  } catch (err) {
    // Protocol errors land here
    // Reset the parser. Otherwise new commands can't be processed properly
    parser.reader = new hiredis.Reader(parser.options)
    parser.returnFatalError(new ParserError(err.message, JSON.stringify(data), -1))
  }
}
github NodeRedis / node-redis-parser / benchmark / oldParser.js View on Github external
'use strict'

const Buffer = require('buffer').Buffer
const StringDecoder = require('string_decoder').StringDecoder
const decoder = new StringDecoder()
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
var bufferPool = Buffer.allocUnsafe(32 * 1024)
var bufferOffset = 0
var interval = null
var counter = 0
var notDecreased = 0

/**
 * Used for integer numbers only
 * @param {JavascriptRedisParser} parser
 * @returns {undefined|number}
 */
function parseSimpleNumbers (parser) {
  const length = parser.buffer.length - 1
  var offset = parser.offset
  var number = 0
  var sign = 1
github NodeRedis / node-redis-parser / lib / parser.js View on Github external
'use strict'

const Buffer = require('buffer').Buffer
const StringDecoder = require('string_decoder').StringDecoder
const decoder = new StringDecoder()
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
var bufferPool = Buffer.allocUnsafe(32 * 1024)
var bufferOffset = 0
var interval = null
var counter = 0
var notDecreased = 0

/**
 * Used for integer numbers only
 * @param {JavascriptRedisParser} parser
 * @returns {undefined|number}
 */
function parseSimpleNumbers (parser) {
  const length = parser.buffer.length - 1
  var offset = parser.offset
  var number = 0
  var sign = 1

redis-errors

Error classes used in node_redis

MIT
Latest version published 7 years ago

Package Health Score

65 / 100
Full package analysis