npm.io
0.1.1 • Published 7 years ago

@laborx/gulp-trycatch

Licence
AGPL-3.0
Version
0.1.1
Deps
1
Size
38 kB
Vulns
0
Weekly
0

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 - if false then an error will be propagated and rethrown and sureTask will eventually fail, if true then sureTask will succeed.