Skip to content

Instantly share code, notes, and snippets.

@nateabele

nateabele/trace.js

Created Dec 1, 2016
Embed
What would you like to do?
Generates friendly trace info for pipe() / compose()
// 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
You can’t perform that action at this time.