Skip to content

Explain error handling Boolean vs function #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tasks": {
"build": "npm install",
"test": "npm install && npm test",
"launch": "node index.js"
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ Handle errors in underlying streams and output them to console.
* `false` - error handler will not be attached.
* `true` - default error handler will be attached.

### Explanation of error handling

The difference between using the default `true` Boolean for the error handler and using a custom function is in how errors are handled and logged.

* The default `true` Boolean uses the `defaultErrorHandler` in `index.js` to log errors without stopping the stream.
* A custom function with `this.emit('end')` logs errors and ends the stream, allowing it to continue.
* A custom function provides more control over error handling behavior.
* The default handler is simpler but less flexible.
* Both options attach error handlers to the stream's `on('error')` event.

### plumber.stop()

This method will return default behaviour for pipeline after it was piped.
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function defaultErrorHandler(error) {
}
}

// The difference between the default `true` Boolean and a custom function for the error handler:
// - The default handler logs errors without stopping the stream.
// - A custom function can log errors and end the stream, allowing it to continue.

function plumber(opts) {
opts = opts || {};

Expand Down
Loading