Skip to content

Add throwOnError configuration option to tanstack-query plugin #2135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

johnny-mh
Copy link
Contributor

Currently, all generated queries have the throwOnError option set to true by default. This works well for new projects or when all components using these queries properly implement error boundaries.

However, in cases where error boundaries are not appropriately set up, developers may need to manually remove this option from each generated query, which can be cumbersome.

This PR introduces a configuration option that allows users to control whether the throwOnError option should be included in generated queries, providing more flexibility for different project setups.

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

vercel bot commented Jun 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hey-api-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 2:23pm

Copy link

changeset-bot bot commented Jun 5, 2025

⚠️ No Changeset found

Latest commit: 1977006

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

pkg-pr-new bot commented Jun 5, 2025

Open in StackBlitz

@hey-api/client-axios

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-axios@2135

@hey-api/client-fetch

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-fetch@2135

@hey-api/client-next

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-next@2135

@hey-api/client-nuxt

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-nuxt@2135

@hey-api/nuxt

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2135

@hey-api/openapi-ts

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2135

@hey-api/vite-plugin

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2135

commit: 1977006

Copy link

codecov bot commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.

Project coverage is 21.84%. Comparing base (80da269) to head (1977006).

Files with missing lines Patch % Lines
...ugins/@tanstack/query-core/infiniteQueryOptions.ts 0.00% 7 Missing ⚠️
...rc/plugins/@tanstack/query-core/mutationOptions.ts 0.00% 7 Missing ⚠️
.../src/plugins/@tanstack/query-core/plugin-legacy.ts 0.00% 7 Missing ⚠️
...s/src/plugins/@tanstack/query-core/queryOptions.ts 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2135      +/-   ##
==========================================
- Coverage   21.84%   21.84%   -0.01%     
==========================================
  Files         271      271              
  Lines       24969    24977       +8     
  Branches      865      865              
==========================================
  Hits         5455     5455              
- Misses      19508    19516       +8     
  Partials        6        6              
Flag Coverage Δ
unittests 21.84% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mrlubos
Copy link
Member

mrlubos commented Jun 5, 2025

Can you explain how this works? Are you silently swallowing errors when it's set to false?

@johnny-mh
Copy link
Contributor Author

When throwOnError is set to true and error boundaries are not properly implemented, errors will bubble up and potentially crash the entire component tree or application. This forces developers to either:

  1. Set up error boundaries throughout their application, or
  2. Manually remove throwOnError: true from every generated query

This configuration option doesn't silently swallow errors - it simply gives developers the choice to handle errors at the query level (using the error property returned by the hook) rather than requiring error boundaries.

With throwOnError: false, errors are still captured and accessible via the query's error state, allowing developers to handle them explicitly in their components as needed.

@mrlubos
Copy link
Member

mrlubos commented Jun 5, 2025

@johnny-mh Can you share some code with me? I'm struggling to understand how errors get captured in the query's error field when we cherry pick only data inside the generated code and the SDK function never throws?

@johnny-mh
Copy link
Contributor Author

I've prepared a demo example that demonstrates this use case. Please feel free to review it when convenient.

Thank you!

https://stackblitz.com/edit/vitejs-vite-3b8gdgjy?file=src%2FApp.tsx

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.

2 participants