JSPM

pull-error-mapper

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q19284F

Map pull-stream errors.

Package Exports

  • pull-error-mapper

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pull-error-mapper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pull-error-mapper

Map pull-stream errors.

Pull-streams, will automatically send your errors downstream.

Errors should be handled in Sinks or in Through streams.

This module, creates a Through stream that can map errors. You can whether map errors or handle them.

Usage

errorMapper(mapper)

mapper is a function that should map or handle the error. If the function returns something, errorMapper will send the returned error downstream. If it returns null or undefined (basically nothing), the error would be considered as handled and the Through stream will read once again.

Example

var pull = require("pull-stream");
var errorMapper = require("pull-error-mapper");

var randomErrorStream = pull.Through( function (read) {
  return function (end, cb) {
    read(end, function (end, data) {
      if (end) return cb(end);

      if (Math.round(Math.random()*3) === 0)
        return cb(new Error("Dummy Error"));

      cb(end, data);
    })
  }
})

// Without ErrorMapper
pull(
  pull.values([1,2,3,4,5,6]),
  randomErrorStream(),
  pull.drain(console.log)
)

/*
  Result: (won't continue sinking after an error happened
  1
  2
 */

// With ErrorMapper
console.log("\n=======\n");
pull(
  pull.values([1,2,3,4,5,6]),
  randomErrorStream(),
  errorMapper(console.error),
  pull.drain(console.log)
)

/*
  Result: (kept sinking even 4 generated an error)
 1
 2
 3
 5
 6
 [Error: Dummy Error]
 */

install

With npm do:

npm install pull-error-mapper

license

MIT