Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parts of stack trace missing when promise rejects #32

Open
SimonSiefke opened this issue Jan 17, 2023 · 3 comments
Open

parts of stack trace missing when promise rejects #32

SimonSiefke opened this issue Jan 17, 2023 · 3 comments

Comments

@SimonSiefke
Copy link

When passing a promise to pTimeout that rejects, error.stack ends at p-timeout/index.js:92:13

Example 1:

import pTimeout from "p-timeout";
import { setTimeout } from "node:timers/promises";

const a = async () => {
  await setTimeout(1);
  throw new Error("oops");
};

const b = async () => {
  await pTimeout(a(), { milliseconds: 500 });
};

try {
  await b();
} catch (error) {
  console.log(error.stack);
}

Example 1 output:

Error: oops
    at a (file:///tmp/index.js:6:9)
    at async file:///tmp/node_modules/p-timeout/index.js:92:13


Example 2:

import { setTimeout } from "node:timers/promises";

const a = async () => {
  await setTimeout(1);
  throw new Error("oops");
};

const b = async () => {
  await a();
};

try {
  await b();
} catch (error) {
  console.log(error.stack);
}

Example 2 output:

Error: oops
    at a (file:///tmp/index.js:6:9)
    at async b (file:///tmp/indexjs:10:3)
    at async file:///tmp/index.js:14:3

In Example 1, these parts are missing from error.stack:

   at async b (file:///tmp/index.js:10:3)
   at async file:///tmp/index.js:14:3
@sindresorhus
Copy link
Owner

It's because of the async-IIFE:

(async () => {

This is really just a limitation in JavaScript engines: https://stackoverflow.com/a/68081429/64949

@silverwind
Copy link

I suppose you could just remove the IIFE and make the parent function async.

@Sadegh-bj
Copy link

When passing a promise to pTimeout that rejects, error.stack ends at p-timeout/index.js:92:13

Example 1:

import pTimeout from "p-timeout";

import { setTimeout } from "node:timers/promises";



const a = async () => {

  await setTimeout(1);

  throw new Error("oops");

};



const b = async () => {

  await pTimeout(a(), { milliseconds: 500 });

};



try {

  await b();

} catch (error) {

  console.log(error.stack);

}

Example 1 output:


Error: oops

    at a (file:///tmp/index.js:6:9)

    at async file:///tmp/node_modules/p-timeout/index.js:92:13



Example 2:

import { setTimeout } from "node:timers/promises";



const a = async () => {

  await setTimeout(1);

  throw new Error("oops");

};



const b = async () => {

  await a();

};



try {

  await b();

} catch (error) {

  console.log(error.stack);

}

Example 2 output:


Error: oops

    at a (file:///tmp/index.js:6:9)

    at async b (file:///tmp/indexjs:10:3)

    at async file:///tmp/index.js:14:3


In Example 1, these parts are missing from error.stack:


   at async b (file:///tmp/index.js:10:3)

   at async file:///tmp/index.js:14:3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants