Skip to content

Instantly share code, notes, and snippets.

@fasterthanlime
Created April 30, 2017 13:32
Show Gist options
  • Save fasterthanlime/fbce0d8188012358d16a6371a44de94d to your computer and use it in GitHub Desktop.
Save fasterthanlime/fbce0d8188012358d16a6371a44de94d to your computer and use it in GitHub Desktop.
async function main () {
const noop = async () => null;
const cherrypie = async () => {
// throwing here is fine...
// the next line loses stack trace info. comment it out to see it working
await noop();
// throwing here is useless
throw new Error("in c");
}
const binomial = async () => await cherrypie();
const abacus = async () => await binomial();
await checkStack(abacus());
}
async function checkStack(promise) {
let threw = false;
try {
await promise;
} catch (e) {
threw = true;
let seen = { a: false, b: false, c: false };
for (const line of e.stack.split("\n")) {
if (/at abacus /.test(line)) {
seen.a = true;
}
if (/at binomial /.test(line)) {
seen.b = true;
}
if (/at cherrypie /.test(line)) {
seen.c = true;
}
}
if (!seen.a || !seen.b || !seen.c) {
// tslint:disable-next-line
console.log(`No trace of a/b/c in stack!`);
console.log(`Offensive stack trace:\n${e.stack}`);
process.exit(1);
} else {
console.log(`Seen a, b, and c!`);
console.log(`Proper stack trace:\n${e.stack}`);
}
}
if (!threw) {
throw new Error(`should reject`);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment