Skip to content

fix(angular-query): honor per-query 'throwOnError' in 'injectQueries' 🤖🤖🤖 - #11405

Open
ousamabenyounes wants to merge 1 commit into
TanStack:mainfrom
ousamabenyounes:fix/issue-8704
Open

fix(angular-query): honor per-query 'throwOnError' in 'injectQueries' 🤖🤖🤖#11405
ousamabenyounes wants to merge 1 commit into
TanStack:mainfrom
ousamabenyounes:fix/issue-8704

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

injectQueries never looked at throwOnError. Its QueriesObserver subscriber wrote every
notification straight into the result signal, so a query failing with throwOnError: true was
silently reduced to an error result — nothing was thrown, and nothing reached Angular's error
handling.

injectQuery already handles this in create-base-query.ts: it calls shouldThrowError with
the query's own throwOnError, emits on NgZone.onError, and rethrows. This applies the same
handling in injectQueries, resolving the option per query — each entry in the array carries
its own throwOnError, so the query that opts in is the one that throws, checked against its own
error and its own Query. react-query's useQueries resolves it per query the same way.

The results are published to the signal before the throw. throwOnError means "also throw", so
the failing query's own status()/error() and its healthy siblings must still update; throwing
first would leave the whole array frozen at its previous value.

Behaviour without throwOnError is unchanged — the errored result still flows into the result
signal, which the existing should reflect error state when one of the queries rejects test covers.

This is one item from the injectQueries TODO list left on #8704 ("Should be able to throw an
error when throwOnError is true"). The other items there are untouched, so this does not close
the issue, and the "under development" note in the Angular parallel-queries guide still applies.

Test verification (RED → GREEN)

Run the angular-query-experimental package's test:lib target from the repo root through
Nx, filtered to inject-queries.

RED — the three new tests against unmodified main (production file reverted, tests kept):

 ❯ src/__tests__/inject-queries.test.ts (7 tests | 3 failed)
       × should throw when throwOnError is true
       × should keep the queries observable after throwing
       × should evaluate throwOnError with the error and query of the failing query only

AssertionError: promise resolved "{ …(45) }" instead of rejecting
AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times

 Test Files  1 failed | 1 passed (2)
      Tests  3 failed | 11 passed (14)

GREEN — same command with the change applied:

 Test Files  2 passed (2)
      Tests  14 passed (14)
Type Errors  no errors

Full local suite

Replayed the pr.yml target set (test:sherif, test:knip, test:docs, test:eslint,
test:lib, test:types, test:build, build) over the affected projects, on main and on
this branch:

angular-query-experimental angular-query-persist-client
main 25 files / 227 passed 5 passed, 1 todo
this branch 25 files / 230 passed 5 passed, 1 todo

No type errors, no lint errors, no new failures. test:types passes on TS 5.6/5.7/5.8/5.9/
current/7.0.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • injectQueries now honors each query’s throwOnError setting.
    • Configured errors are thrown correctly while query status and error details remain available.
    • Other queries continue updating normally when one query throws an error.
  • Documentation

    • Added a patch release note for the Angular Query experimental package.

injectQueries never evaluated throwOnError, so a failing query with
throwOnError set was silently reduced to an error result. Resolve the
option per query in the QueriesObserver subscriber and rethrow, the way
injectQuery already does in createBaseQuery. Results are published to the
signal before the throw so the failing query's own error state and its
healthy siblings still update.
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: e8acfd0d-2bf1-423c-89b1-cef8a091a151

📥 Commits

Reviewing files that changed from the base of the PR and between 1893a96 and f446e85.

📒 Files selected for processing (3)
  • .changeset/angular-inject-queries-throw-on-error.md
  • packages/angular-query-experimental/src/__tests__/inject-queries.test.ts
  • packages/angular-query-experimental/src/inject-queries.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

injectQueries now publishes query results before evaluating per-query throwOnError settings. Matching query errors are emitted through Angular’s error handler and thrown. Tests cover error propagation, sibling updates, error states, and callback arguments.

Changes

Angular injectQueries error handling

Layer / File(s) Summary
Per-query error throwing
packages/angular-query-experimental/src/inject-queries.ts
The subscriber publishes results, evaluates each errored non-fetching query with its own throwOnError option, and throws matching errors through ngZone.onError.
Behavior tests and release metadata
packages/angular-query-experimental/src/__tests__/inject-queries.test.ts, .changeset/angular-inject-queries-throw-on-error.md
Tests cover thrown errors, sibling query updates, error states, and throwOnError callback arguments. The changeset records a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to f446e

injectQueries now applies throwOnError per failing query while preserving published error and sibling-query states before rethrowing. The covered behavior is ready to merge with no identified current risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: injectQueries now honors per-query throwOnError options. The wording is concise and specific, although the emojis are unnecessary.
Description check ✅ Passed The description follows the required template. It explains the change and motivation, documents testing, completes the checklist, and includes the appropriate changeset release impact.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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