Skip to content

bug(core): Promise.all in collectionItemsResult — one failing sanitizeItem rejects the entire collection #275

Closed

Description

@vamgan

Summary

In packages/core/src/sources.ts, the collection source resolves all items through sanitizeItem in a single Promise.all. If any single item's sanitizer rejects, the entire collection resolve fails — no items are returned, and the source emits an error instead of a partial result.

Root cause

const serialized = options.sanitizeItem
  ? await Promise.all(capped.map((item) => options.sanitizeItem!(item, request)))
  : [...capped];

A single rejected promise in the array causes Promise.all to reject immediately, discarding all other successfully sanitized items.

Expected behaviour

Depending on the configured sourceErrorMode, a failing item should either:

  • Be omitted from results (leaving the rest intact)
  • Be replaced with an error placeholder
  • Reject the whole collection only if sourceErrorMode: 'throw'

Fix

Use Promise.allSettled and filter/handle rejections:

const results = await Promise.allSettled(
  capped.map((item) => options.sanitizeItem!(item, request))
);
const serialized = results
  .filter((r): r is PromiseFulfilledResult<unknown> => r.status === 'fulfilled')
  .map((r) => r.value);

Impact

Any app using sanitizeItem to redact/transform items where one item could fail (e.g. async fetch for enrichment) will silently lose the entire collection rather than a graceful partial result.

Activity

  1. added
    bugSomething isn't working
    area: coreCore package and cross-package runtime behavior
    on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreCore package and cross-package runtime behaviorbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions