Repository navigation
Commit 83fc096
fix(data-objectstack): a ConnectionError nothing answered no longer carries an invented 503 (#29947)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwB4xjiquevJqfBXiUoqfQwa1)_
Fixes #29916
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:后端连不上时(主机不可达、请求被浏览器直接拒绝),适配器的 `ConnectionError` 不再带一个编造的
503;服务器真正回答过的 503/504 照旧带状态码,发现接口被服务器以错误状态拒绝时带的是服务器的真实状态。
- **为什么改**:带着 503 的断网错误被列表页、记录页等读取方当成「服务器已回答」,于是把浏览器的 "Failed to fetch"
当成服务器原话展示,而不是提示用户检查网络;#29915 修了 `createErrorFromResponse`
的同类问题,这是剩下的那个来源。
- **风险与回滚**:风险低。只在没传状态码时行为变化(`statusCode` 由 503 变为未定义,错误类与 code
不变);仓内没有任何读取方按 503 分支;回滚即还原本 PR。
- **先看**:`ui/packages/data-objectstack/src/errors.ts`(构造器去掉 `||
503`)、`ui/packages/data-objectstack/src/index.ts`(`connect()` 的 catch
与发现接口 `!res.ok`
分支)、`ui/packages/react/src/utils/error-message.adapter-connection-unanswered-29916.test.ts`(真实适配器
+ 共享读取规则的边界钉)。
- **两分钟验证**:在仓根运行 `pnpm --dir ui exec vitest run
packages/react/src/utils/error-message.adapter-connection-unanswered-29916.test.ts
packages/data-objectstack/src/connectRetriesDiscovery-12318.test.ts`,预期
9 个测试全部通过,其中断网用例读作 `network`,已回答的 503 用例读作已回答。
- **需要你做的**:无,席位落地。
## What changes
The `ConnectionError` constructor no longer invents a status. It stamped
`statusCode || 503`; it now passes `statusCode` through, so an error
built without one keeps `statusCode` undefined. Same shape as #29915 for
`createErrorFromResponse`.
I moved the default in the constructor, not at the two callers. The
constructor's only status input is an optional number, so a caller could
not say "no answer" to it. Every caller that omits a status is a
no-answer path.
Every `new ConnectionError(` caller, and what it carries now:
| Caller | Path | Before | After |
|---|---|---|---|
| `index.ts` `connect()` catch, discovery `fetch` rejected | nothing
answered | 503 (invented) | none |
| `index.ts` `connect()` catch, discovery answered `!res.ok` | server
answered | 503 (invented, whatever the server said) | the server's
status (`res.status`) |
| `index.ts` `noteServerUnanswered` (post-connect `error` state) |
nothing answered | 503 (invented) | none |
| `errors.ts` `createErrorFromResponse` case 503 | server answered | 503
| 503 (unchanged) |
| `errors.ts` `createErrorFromResponse` case 504 | server answered | 504
| 504 (unchanged) |
Why the second row matters: the `connect()` catch covers both a rejected
`fetch` and a discovery the server refused. Dropping the default alone
would have flipped an answered discovery failure from "answered (wrong
status)" to "unanswered". So the `!res.ok` throw now puts `status:
res.status` on its error, and the catch hands a numeric `status` to the
constructor. A discovery 401 now reads as `unauthorized`.
Every data method opens with `await this.connect()`. So a list or record
read against an unreachable backend rejects with the `connect()` error,
and `answeredLoadFailure` / `classifyLoadError` read it. After this PR
that read returns `null` and classifies as `network`.
**Exported contract (the PM's mechanism assumption, measured):**
`ConnectionError` and `ObjectStackError.statusCode?: number` are
exported. The TypeScript type is unchanged, since `statusCode` was
already optional. The runtime value changes for `new
ConnectionError(msg)` with no status: `503` becomes `undefined`. Docs
that describe it:
- `ui/packages/data-objectstack/README.md` L582 calls it
"Network/connection errors (503/504)". That still describes the answered
503/504 cases, but it does not say a no-answer error carries no status.
- `content/docs/frontend/data-objectstack.mdx` L497 shows "`code
'CONNECTION_ERROR', statusCode 503`" for a `getObjectSchema` failure.
That path only builds a `ConnectionError` from an answered 503/504
(no-answer goes through `createErrorFromResponse` to `UNKNOWN_ERROR`
since #29915), so it stays true.
I left both docs as they are, because neither is in the claimed file
surface. A wording follow-up for the README line is in the report.
## Tests
- New
`ui/packages/react/src/utils/error-message.adapter-connection-unanswered-29916.test.ts`.
It sits next to #29915's boundary pin, because the adapter cannot import
`answeredLoadFailure` (react depends on data-objectstack). It drives the
real `ObjectStackAdapter` over a fake `fetch`:
- `connect()` over a rejecting `fetch`: `ConnectionError`, `statusCode`
undefined, `answeredLoadFailure` null, `classifyLoadError` `network`.
- `find()` before connect with discovery unreachable: same.
- after a good connect, an unanswered `find()` trips
`noteServerUnanswered`: the `error` state event's `ConnectionError` has
no status, null, `network`.
- CONTROL: `createErrorFromResponse({ status: 503 })` keeps 503 and
reads as answered.
- CONTROL: a discovery the server answered with 503 keeps 503 and reads
as answered.
- a discovery answered 401 carries 401 and classifies `unauthorized`.
- **Moved pin:** `connectRetriesDiscovery-12318.test.ts`, "refused past
the budget". It asserted `statusCode: 503` on a discovery that was
refused and never answered. It now asserts `statusCode` undefined.
- `errors.test.ts`: the bare-constructor pin moves from 503 to
undefined. A new CONTROL checks that a passed 503 / 504 is kept.
## Acceptance notes
- A test file outside the claimed surface: the new pin lives in
`ui/packages/react/src/utils/`, not in data-objectstack. This is
#29915's precedent, for the reason above. No other file outside the
claim is touched.
- No consumer in `ui/` branches on a `ConnectionError`'s 503. I grepped
`statusCode === 503`, `status === 503` and `CONNECTION_ERROR` outside
tests. The two 503 hits (`metadata-admin/external/api.ts`,
`preview/commitHistory.ts`) read raw `fetch` responses, not this class.
## Verification
All of it ran on head `7aaf1de9`.
- `pnpm --dir ui exec vitest run packages/data-objectstack/
packages/react/src/utils/` (under the verify lock): VERDICT command-exit
0, 123 files and 1407 tests passed.
- Consumer sweep: all 60 test files outside data-objectstack that build
a real `ObjectStackAdapter` (app-shell, console and others, found with
`grep -rl "new ObjectStackAdapter|createObjectStackAdapter"`). VERDICT
0, 60 files and 487 tests passed.
- `cd ui && pnpm exec turbo run build type-check
--filter=@object-ui/data-objectstack --filter=@object-ui/react`: VERDICT
0, 44/44 tasks. `@object-ui/data-objectstack:type-check` and
`@object-ui/react:type-check` are both in the output.
- `node scripts/check-sdui-manifest.mjs`: exit 0, intact, 106
components.
- Ablation, on committed head `7aaf1de9` with
`scripts/ablation-replace.mjs`. Vitest aliases
`@object-ui/data-objectstack` to `src`, so no dist rebuild was needed.
- I put `statusCode || 503` back in the constructor. 5 tests went red:
the moved 12318 pin, the `errors.test.ts` bare-constructor pin, and the
three no-answer pins in the new file. The other 1402 stayed green,
including every CONTROL. On restore, the blob was `35dfadc2` == HEAD and
`git diff HEAD` was empty.
- I dropped the discovery status hand-off (passed `undefined`). 2 tests
went red: the answered-503 discovery CONTROL and the 401 pin. The other
4 stayed green. On restore, the blob was `2098bca3` == HEAD.
<details><summary>Derived gates: dispatch-gates --commands, 36 at
7aaf1de, all exit 0; --ran: 36 derived, 36 run, 0
NOT-MEASURED</summary>
```text
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-sdui-manifest.mjs :: exit 0
node scripts/check-sdui-manifest.mjs --self-test :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --dir ui exec vitest run scripts/ :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:error-status-conformance :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:skill-identifier-liveness :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
```
`pnpm --dir ui exec vitest run scripts/`: 170 files passed, 2 skipped
(4979 tests).
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (CI runs it)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English. (except the 维护者速读
block the dispatch contract requires)
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzfeRhCDTUFg4Reps3f
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1f6bc5a commit 83fc096
6 files changed
Lines changed: 173 additions & 5 deletions
File tree
- .changeset
- ui/packages
- data-objectstack/src
- react/src/utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
160 | 163 | | |
161 | 164 | | |
162 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
| |||
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
165 | 172 | | |
166 | 173 | | |
167 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
124 | 134 | | |
125 | 135 | | |
126 | 136 | | |
| |||
132 | 142 | | |
133 | 143 | | |
134 | 144 | | |
135 | | - | |
| 145 | + | |
136 | 146 | | |
137 | 147 | | |
138 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3613 | 3613 | | |
3614 | 3614 | | |
3615 | 3615 | | |
3616 | | - | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
3617 | 3622 | | |
3618 | 3623 | | |
3619 | 3624 | | |
| |||
3635 | 3640 | | |
3636 | 3641 | | |
3637 | 3642 | | |
| 3643 | + | |
| 3644 | + | |
| 3645 | + | |
| 3646 | + | |
3638 | 3647 | | |
3639 | 3648 | | |
3640 | 3649 | | |
3641 | | - | |
| 3650 | + | |
| 3651 | + | |
3642 | 3652 | | |
3643 | 3653 | | |
3644 | 3654 | | |
| |||
3788 | 3798 | | |
3789 | 3799 | | |
3790 | 3800 | | |
| 3801 | + | |
3791 | 3802 | | |
3792 | 3803 | | |
3793 | 3804 | | |
| |||
| 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 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 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 | + | |
0 commit comments