Repository navigation
Commit 1df6f2b
## Problem
`onError`, `onFinish`, `onAsyncIteratorObjectError` and
`onReadableStreamError` inferred the error type with:
```ts
ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError
```
`PromiseWithError<T, E>` is `Promise<T> & { __error?: { type: E } }`.
`__error` is optional, so a plain `Promise` already matches with `E =
unknown`. The `ThrowableError` fallback was only reached when `next()`
didn't return a promise, which made the result inconsistent: a plain
promise gave `unknown`, but a non-promise return gave `Error`.
## Fix
Add an exported `InferNextError<TOptions>` type and use it in all four
helpers. It infers `E` from `PromiseWithError` when `next()` carries a
typed error, and gives `unknown` otherwise. There is no longer a
`ThrowableError` fallback.
- Typed `PromiseWithError` errors (e.g. `clientInterceptors`) behave as
before.
- Plain-promise `next()` (handler `interceptors` and
`routingInterceptors`) gives `unknown`, as before.
- Non-promise `next()` now gives `unknown` instead of `ThrowableError`.
- `onAsyncIteratorObjectError` and `onReadableStreamError` still union
the inferred error with `ThrowableError`, so with no typed error they
give `unknown`.
## Tests
- `packages/shared/src/interceptor.test-d.ts`: new cases for a
plain-promise `next()` and a non-promise `next()`. The non-promise case
fails on `main`, where the error was `Error`.
- `packages/server/src/adapters/fetch/rpc-handler.test-d.ts` (new): pins
`unknown` for `onError` and `onFinish` in `RPCHandler` `interceptors`
and `routingInterceptors`.
`pnpm check` and `pnpm test` pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01VVaw7P6j7fKqfLdPENbs1h
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 850fec8 commit 1df6f2b
3 files changed
Lines changed: 89 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
| |||
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 91 | + | |
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
| |||
127 | 125 | | |
128 | 126 | | |
129 | 127 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 128 | + | |
135 | 129 | | |
136 | 130 | | |
137 | 131 | | |
| |||
175 | 169 | | |
176 | 170 | | |
177 | 171 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 172 | + | |
183 | 173 | | |
184 | 174 | | |
185 | 175 | | |
| |||
0 commit comments