0.1.1 • Published 5 years ago

@laborx/gulp-trycatch v0.1.1

Weekly downloads
-
License
AGPL-3.0
Repository
gitlab
Last release
5 years ago

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.