Skip to content

Instantly share code, notes, and snippets.

@DCoomer
Created November 27, 2023 15:36
Show Gist options
  • Save DCoomer/4cab048108f08c44f78d9143fe3e4f01 to your computer and use it in GitHub Desktop.
Save DCoomer/4cab048108f08c44f78d9143fe3e4f01 to your computer and use it in GitHub Desktop.
Get stack trace for FS async (Solution for https://github.com/nodejs/node/issues/30944)
// Wrap the caught error in a new Error to get full stacktrace
const fs = require(`fs`);
try {
await fs.promises.readFile(`filePath`).catch((err)=>{
throw new Error(err);
});
} catch (error) {
console.error(error);
}
// or
fs.readFile(`filePath`, (err)=>{
if (err) throw new Error(err);
});
@DCoomer
Copy link
Author

DCoomer commented Nov 27, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment