Skip to content

Instantly share code, notes, and snippets.

@nateabele
Created December 1, 2016 07:19
Show Gist options
  • Save nateabele/9c55ef3942a8b24f2140d8f05ec257bf to your computer and use it in GitHub Desktop.
Save nateabele/9c55ef3942a8b24f2140d8f05ec257bf to your computer and use it in GitHub Desktop.
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