0.1.1 • Published 7 years ago
@laborx/gulp-trycatch v0.1.1
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- iffalsethen an error will be propagated and rethrown andsureTaskwill eventually fail, iftruethensureTaskwill succeed.
0.1.1
7 years ago