github →

Request

Issue #34

draft pr open
What we changed

Renamed the call-site capture variable in index.js from error to hostError and changed its message to 'p-map'. The stack-trace preservation logic now reads hostError.stack instead of error.stack, splitting the captured lines with .split('n'), slicing from index 2, and joining them as callerStack to append to mapper rejections.

Verification
Verified — checks passed

We installed dependencies and ran test in a sandbox — all passed.

Likely addresses the issue (90% confidence)

An AI estimate of whether the change actually fixes the issue — the checks themselves only confirm nothing broke. It's a hint for review, not a pass/fail check.

Why?

The diff creates a `hostError` at the start of `pMap` to snapshot the caller stack, then in the `reject` handler it strips the internal p-map frames and appends the remaining caller frames to the thrown error’s stack. This directly fixes the reported truncation so callers like `runPromisePmap` appear in the trace, which the new test explicitly asserts.

  • testpassed · 12.4s
    > p-map@7.0.4 test
    > xo && ava && tsd
    
    
      ✔ test › handles empty iterable
      ✔ test › asyncIterator - handles empty iterable
      ✔ test › pMapIterable - empty
      ✔ test › invalid mapper
      ✔ test › already aborted signal
      ✔ test › pMapIterable - iterable that throws
      ✔ test › pMapSkip
      ✔ test › preserves async stack trace
      ✔ test › pMapIterable - mapper that throws
      ✔ test › all pMapSkips
      ✔ test › multiple pMapSkips
      ✔ test › pMapIterable - pMapSkip
      ✔ test › enforce number in options.concurrency
      ✔ test › asyncIterator - enforce number in options.concurrency
      ✔ test › asyncIterator - pMapSkip
      ✔ test › asyncIterator - all pMapSkips
      ✔ test › abort by AbortController
      ✔ test › asyncIterator - multiple pMapSkips (110ms)
      ✔ test › no unhandled rejected promises from mapper throws - infinite concurrency (111ms)
      ✔ test › no unhandled rejected promises from mapper throws - concurrency 1 (110ms)
      ✔ test › pMapIterable - stop on error (110ms)
      ✔ multiple-pmapskips-performance › multiple pMapSkips - algorithmic complexity (172ms)
      ✔ test › async with concurrency: 2 (out of order time sequence) (216ms)
      ✔ test › async with concurrency: 2 (problematic time sequence) (221ms)
      ✔ test › asyncIterator - async with concurrency: 2 (out of order time sequence) (223ms)
      ✔ test › async with concurrency: 2 (random time sequence) (268ms)
      ✔ test › asyncIterator - async with concurrency: 2 (problematic time sequence) (268ms)
      ✔ test › asyncIterator - async with concurrency: 2 (random time sequence) (268ms)
      ✔ test › main (318ms)
      ✔ test › pMapIterable (306ms)
      ✔ test › pMapIterable - async input, backpressure > concurrency (310ms)
      ✔ test › catches exception from source iterator - 1st item (315ms)
      ✔ test › asyncIterator - main (324ms)
      ✔ test › pMapIterable - concurrency: 2 (357ms)
      ✔ test › catches exception from source iterator - 2nd item (409ms)
      ✔ test › catches exception from source iterator - 2nd item after 1st item mapper throw (411ms)
      ✔ test › asyncIterator - get the correct exception after stop-on-error (500ms)
      ✔ test › incorrect input type (500ms)
      ✔ test › immediately rejects when stopOnError is true (536ms)
      ✔ test › asyncIterator - immediately rejects when stopOnError is true (584ms)
      ✔ test › all mappers should run when concurrency is infinite, even after stop-on-error happened (612ms)
      ✔ test › concurrency: 1 (619ms)
      ✔ test › pMapIterable - concurrency: 1 (608ms)
      ✔ test › pMapIterable - index in mapper (609ms)
      ✔ test › asyncIterator - all mappers should run when concurrency is infinite, even after stop-on-error happened (623ms)
      ✔ test › asyncIterator - concurrency: 1 (645ms)
      ✔ test › pMapIterable - backpressure (1s)
      ✔ test › aggregate errors when stopOnError is false (1.2s)
      ✔ test › asyncIterator - aggregate errors when stopOnError is false (1.3s)
      ✔ test › concurrency: 4 (2.9s)
      ✔ test › asyncIterator - concurrency: 4 (3.2s)
      ─
    
      51 tests passed
    
    npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
    npm warn Unknown user config "dangerously-allow-all-builds". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.
    npm warn Unknown user config "verify-deps-before-run". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.

lint, typecheck, and build are not defined separately in this repo.

Ran 6/10/2026, 11:49:38 PM · npm

Get the code

Pull this branch
With gh CLI
gh pr checkout 18 --repo kamransiddiqui/p-map
Raw git
git fetch https://github.com/kamransiddiqui/p-map.git gitgot/issue-34
git checkout -b gitgot/issue-34 FETCH_HEAD

Fork-mode request: the branch lives on kamransiddiqui/p-map (your fork), not sindresorhus/p-map, so the commands above target the fork.

Drive locally

Paste this into your local coding agent (Claude Code, Cursor, etc.) to continue iterating with full repo context.

Context prompt
You are continuing work on a draft PR for sindresorhus/p-map, addressing issue #34.

First, check out the branch with gitgot's first-pass change (run from a clone of the repo):
  gh pr checkout 18 --repo kamransiddiqui/p-map

Then review the diff and:
- run the project's lint/typecheck/test commands and fix anything broken
- if the diff is wrong-headed, revert it and start fresh from the issue
- keep the change tight; do not refactor unrelated code
PR thread