I know that error.stack will give me an error stacktrace. That's fine when the error is created and immediately thrown, but I have some failing code where that's not happening: the error is created in one place, and then thrown somewhere later. I want to know where it's thrown, not where it's created.
Is there any way to find this information? This is a Node.js process (v14).
For context: I'm using some 3rd party code, which internally throws and caches an error, but then appears to handle it correctly. For some reason though, later on that same error instance comes out of the cache and gets thrown, crashing my application. I need to know who's throwing it.
A concrete example:
const err = new Error();
function f() {
throw err;
}
f();
The stacktrace of err only shows the top level. How can I find out that err was thrown in f?