@laborx/gulp-trycatch
v0.1.1
Published
Provides gulp wrapper for intercepting errors in tasks
Downloads
30
Keywords
Readme
Gulp try-catch-finally wrapper
Provides wrapper for handling errors inside series
and paralles
tasks by allowing to set catchTask
and finallyTask
.
Usage
import { tryCatchTaskWrapper } from "@laborx/gulp-trycatch";
export function failTask() {
throws new Error("Cannot finish task in some cases")
}
export function cleanupTask() {
// do some cleanup work that should be done it either way, for example, server port closing or file deletion
}
function observeOptionalErrorFunc(err: any) {
console.error(`Found error during running task ${err}`)
}
// `sureTask` will always execute `cleanupTask` either `failTask` function throws or not
export const sureTask = tryCatchTaskWrapper(failTask, cleanupTask, observeOptionalErrorFunc, { silent: false })
You can pass optional configuration:
silent
- iffalse
then an error will be propagated and rethrown andsureTask
will eventually fail, iftrue
thensureTask
will succeed.