https://github.com/nichoth/pull-catch
Catch errors in a pull stream
https://github.com/nichoth/pull-catch
Last synced: about 1 year ago
JSON representation
Catch errors in a pull stream
- Host: GitHub
- URL: https://github.com/nichoth/pull-catch
- Owner: nichoth
- Created: 2016-11-26T22:57:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-27T19:59:40.000Z (over 2 years ago)
- Last Synced: 2025-05-11T18:17:41.394Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://github.com/nichoth/pull-catch#readme
- Size: 17.6 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# pull catch
Handle errors in pull streams
This is a through stream that can ensure your source stream always ends normally, even when it returns an error. This is useful if you are combining several source streams with pull-many, and you want to keep the remaining streams open even if one of them errors.
## install
$ npm install pull-catch
## example
```js
var test = require('tape')
var S = require('pull-stream')
var Catch = require('../')
test('catch errors', function (t) {
t.plan(2)
S(
S.error(new Error('test')),
Catch(function onErr (err) {
t.equal(err.message, 'test', 'should callback with error')
}),
S.collect(function (err, resp) {
t.error(err, 'should end the stream without error')
})
)
})
test('return false to pass error', function (t) {
t.plan(1)
S(
S.error(new Error('test')),
Catch(function (err) {
return false
}),
S.collect(function (err, res) {
t.equal(err.message, 'test', 'should pass error in stream')
})
)
})
test('return truthy to emit one event then end', function (t) {
t.plan(2)
S(
S.error(new Error('test')),
Catch(function (err) {
return 'test data'
}),
S.collect(function (err, res) {
t.error(err, 'should not end with error')
t.deepEqual(res, ['test data'], 'should emit one event')
})
)
})
test('callback is optional', function (t) {
t.plan(1)
S(
S.error(new Error('test')),
Catch(),
S.collect(function (err, res) {
t.error(err, 'should end stream without error')
})
)
})
```