Skip to content

pooledMap's error message is unhelpful when an error comes from the input async iterable #6716

Open
@notcome

Description

@notcome

Describe the bug

pooledMap's error message is unhelpful when an error comes from the input async iterable. It gives the following message:

Uncaught AggregateError: Cannot complete the mapping as an error was thrown from an item
    at https://jsr.io/@std/async/1.0.13/pool.ts:95:9

But the error is not from a transforming promise

Steps to Reproduce

Run the following code

// Async iterator that throws on first iteration
async function* errorThrowingIterator() {
  throw new Error("Iterator failed on first step!");
  yield 1; // This will never be reached
  yield 2;
  yield 3;
}

// Usage with pooledMap that will trigger the error
import { pooledMap } from "jsr:@std/async/pool";

const results = pooledMap(
  2,
  errorThrowingIterator(),
  async (item) => {
    console.log("Processing:", item); // This won't execute
    return item * 2;
  }
);

We will get

Uncaught AggregateError: Cannot complete the mapping as an error was thrown from an item
    at https://jsr.io/@std/async/1.0.13/pool.ts:95:9

Expected behavior

If the error is not from settled promises, I think we should throw the error from the catch block instead.

Environment

  • OS: macOS 15
  • deno version: 2.3.5
  • std version: 1.0.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions