Skip to content

0.18 PR2: validate strategies, remove fail/stopOnError aliases - #31

Merged
ildella merged 4 commits into
masterfrom
fix-strategy-contract
Nov 24, 2026
Merged

ildella merged 4 commits into
masterfrom
fix-strategy-contract

Conversation

@ildella

@ildella ildella commented Nov 24, 2026

Copy link
Copy Markdown
Owner

What

PR 2 of the 0.18 stabilization plan (fix/strategy-contract).

  • New import-free src/strategy-name.js: strategyNameOf / assertStrategy
    normalize a strategy to its canonical name and throw a TypeError otherwise.
  • Wired into createRunState (so series/filter/scan/reduce/enrich/findSync validate when the operation is built, before the source is pulled), assertRethrowStrategy (mapSeries/mapSeriesSync) and join.
  • Removed the fail and stopOnError aliases from src/strategy.js and the public re-exports.
  • 'rethrow' (string or {name: 'rethrow'}) still works as an alias of 'throw'; mapSeries/mapSeriesSync still only accept rethrow/throw and keep their "always rethrows" error for other strategies.
  • Error messages carry the API name: series(), seriesSync(), scan/reduce(), join(), findSync(), mapSeries(), mapSeriesSync().

Why

An unknown strategy used to fall through every branch in failOnItem/failOnSource and behave like collect — a silent policy change. The aliases were scheduled for removal in 0.18. Both now fail fast with an actionable message.

Tests

  • New tests/strategy-validation.test.js: valid strategy objects on series/filter/folds/enrich/join/findSync, valid strings, rethrow alias behavior, removed aliases (TypeError "use failFast"), unknown values ('failfast', null, 42, {}), validation before the source is pulled, the mapSeries rethrow lock, and no fail/stopOnError in the public namespace.
  • Removed the alias tests from tests/error-strategies.test.js and tests/join-error-strategies.test.js.
  • Updated the two null strategy expectations in the mapSeries/mapSeriesSync tests: unknown names now get the shared "unknown strategy" message.

Docs

README error-model table, guide failFast/rethrow sections, reference TOC/failFast/rethrow/join/matrix, migration 0.18 (Removed: fail / stopOnError, invalid strategies throw), skill already had no aliases.

Verification

  • yarn lint — clean
  • yarn vitest run — 72 files / 967 tests passed
  • yarn check — lint + dup (0 clones) + knip clean

knip.json ignores duplicates for src/strategy-name.js, matching the existing src/strategy.js entry: the plan asks for assertStrategy to be exported as an alias of strategyNameOf, which knip otherwise reports as a duplicate export.

Plan reference: /home/della/.opencode/plan/pipelean-0.18.md, PR 2 (lines 168-255), non-goals/risks sections 4-5.

Unknown strategies were silently treated as collect, and the deprecated
fail/stopOnError aliases outlived their 0.18 removal. Both now raise a
TypeError at construction, naming the API and the accepted values.

'rethrow' stays an alias of 'throw'; mapSeries/mapSeriesSync keep their
rethrow lock and report it in the error.

Plan: 0.18 PR 2 (fix/strategy-contract).
@ildella
ildella marked this pull request as ready for review November 24, 2026 14:36

@ildella ildella left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVED

REVIEW: Both review passes found no valid medium-or-higher issues. A new import-free src/strategy-name.js normalizes strategy identifiers in one place; fail/stopOnError are no longer exported or accepted, 'rethrow' (string and {name}) behaves as 'throw', and unknown strategies throw a TypeError before the source is pulled across series/filter/folds/enrich/join/findSync and the sync twins. README, guide, reference and migration docs are consistent with the new contract.

FINDINGS: No valid medium-or-higher findings. Low/info follow-ups:

  • INFO (reviewer proposed MEDIUM, downgraded) — createRunState carries both label and strategyLabel. These are not duplicated state: label is the optional sync-telemetry name used by assertSyncCallback(state.label, …) and is undefined on async runs, while strategyLabel is the API name for validation errors and is always set. Concretely, async series() has label === undefined, strategyLabel === 'series' — they differ on every async call. Using label alone, as the plan sketch suggests, would make telemetry dispatch treat async runs as sync and reject async callbacks; the separation is intentional and the JSDoc documents it.
  • LOW — validation errors on async filter/enrich name the underlying engine: filter(items, pred, {strategy: 'bogus'}) reports series() unknown strategy ..., and enrich reports scan/reduce(). Trigger: any invalid strategy on those wrappers; behavior is correct and plan-conformant, only the wrapper name is missing from the message.
  • LOW — mapSeries/mapSeriesSync rejected-alias hint points to values they don't accept: mapSeries(..., {strategy: 'fail'}) says use failFast, but failFast is itself rejected by the always-rethrow API. Trigger: a user following the shared message; plan-prescribed wording.
  • LOW — export const assertStrategy = strategyNameOf is a second name for one function (only shared.js imports the alias), and knip.json adds a duplicates suppression for the new module. Trigger: future callers importing either name diverge; plan §2a prescribes the alias, so not blocking.
  • LOW — several tests assert exact error strings, e.g. new TypeError('series() strategy "fail" was removed in 0.18; use failFast'). Trigger: a benign wording change forces multi-file test edits.
  • INFO — the new file repeats the canonical strategy set as objects, strings and "all others" lists; adding a strategy could update only one. Coverage of 'rethrow' on join/folds/findSync and invalid strategies on folds/findSync/enrich is not pinned.
  • INFO — the branch was merged with master after reviews started; the current diff's migration header now correctly reads "one soft deprecation, two additive changes and two breaking ones", resolving the earlier cross-PR conflict with PR 29.

CI: green — the test check (Code Check workflow) succeeded.

@ildella
ildella merged commit 3f9bb22 into master Nov 24, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

1 participant