Commit 9dffe43
committed
fix(api): guard response.text() in error paths and label chars
Addresses Cursor bugbot feedback on PR #1233.
1. `result.text?.()` in the `!result.ok` branches of `queryApiSafeText`
and `sendApiRequest` was unguarded. If `text()` threw, the exception
propagated past the clean `{ ok: false, ... }` return and broke the
error-handling contract. Wrap both call sites in a shared
`tryReadResponseText` helper that swallows the failure and returns
`undefined`.
2. The truncation suffix reported `body.length` as "bytes", but
`String.prototype.length` / `String.prototype.slice` count UTF-16
code units, not bytes. For non-ASCII response bodies the label was
misleading. Rename to "chars" so the counter matches the actual
measurement.1 parent a6ee497 commit 9dffe43
File tree
3 files changed
+19
-4
lines changed- packages/cli
- src/utils
- socket
- test/unit/utils
3 files changed
+19
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
132 | 135 | | |
133 | 136 | | |
134 | | - | |
| 137 | + | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
85 | 97 | | |
86 | 98 | | |
87 | 99 | | |
| |||
485 | 497 | | |
486 | 498 | | |
487 | 499 | | |
488 | | - | |
| 500 | + | |
489 | 501 | | |
490 | 502 | | |
491 | 503 | | |
| |||
674 | 686 | | |
675 | 687 | | |
676 | 688 | | |
677 | | - | |
| 689 | + | |
678 | 690 | | |
679 | 691 | | |
680 | 692 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| |||
0 commit comments