-
-
Couldn't load subscription status.
- Fork 62
Description
Both, console.trace and throw new Error don't show the stack-trace beyond the point p-map got called. In other words, the functions that called before pMap, disappear from the stack trace.
As a comparison, the p-map-series doesn't suffer from this issue. It does keep the stack-trace.
See the example below, if you run a function that runs the native Promise.all, the stack trace shows the function name - runPromiseNative. Same if you run the function runPromisePmapSeries. However, try to run runPromisePmap, and you'll see how the stack trace truncated.
I tried node v12.x and v14.x.
const pMap = require('p-map');
const pMapSeries = require('p-map-series');
async function promiseFn() {
throw new Error('stop')
}
async function runPromiseNative() {
await Promise.all([promiseFn()]).then(() => { console.log('completed') }).catch((err) => console.error(err));
}
async function runPromisePmap() {
await pMap([promiseFn], fn => fn()).then(() => { console.log('completed') }).catch((err) => console.error(err));
}
async function runPromisePmapSeries() {
await pMapSeries([promiseFn], fn => fn()).then(() => { console.log('completed') }).catch((err) => console.error(err));
}
// runPromiseNative();
runPromisePmap();
// runPromisePmapSeries();
Results when running runPromisePmap :
Error: stop
at promiseFn (/Users/davidfirst/teambit/bit/pmap.js:6:9)
at /Users/davidfirst/teambit/bit/pmap.js:14:33
at /Users/davidfirst/teambit/bit/node_modules/p-map/index.js:57:28
Results when running runPromiseNative.
Error: stop
at promiseFn (/Users/davidfirst/teambit/bit/pmap.js:6:9)
at runPromiseNative (/Users/davidfirst/teambit/bit/pmap.js:10:22)
at Object.<anonymous> (/Users/davidfirst/teambit/bit/pmap.js:21:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47