Created
December 1, 2016 07:19
-
-
Save nateabele/9c55ef3942a8b24f2140d8f05ec257bf to your computer and use it in GitHub Desktop.
Generates friendly trace info for pipe() / compose()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use like: trace("Friendly name", pipe)(map(...), filter(...), etc(...)) | |
export const trace = (name, comp) => (...fns) => comp(...fns.map((fn, i) => { | |
return (...args) => { | |
try { return fn(...args); } catch(e) { | |
e.message = `Error in ${comp.name}() sequence ${name} at step ${i} (${fn.name || '<anon>'}()): ${e.message}`; | |
throw e; | |
} | |
}; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment