Commit 35b9b9c
authored
fix(debug): log structured HTTP error details instead of raw response (#1233)
* fix(debug): log structured HTTP error details instead of raw response
When an HTTP request fails, `debugApiResponse` now logs:
* endpoint (description) — already was
* status — already was
* method, url, durationMs — already was
* sanitized request headers (Authorization/api-keys redacted) — already was
And new fields that make support tickets actionable:
* requestedAt — ISO-8601 timestamp of request start, for correlating
with server-side logs.
* cfRay — Cloudflare trace id extracted as a top-level field
from response headers (accepts `cf-ray` or `CF-Ray` casing).
* responseHeaders — sanitized headers returned by the server.
* responseBody — string response body, truncated at 2_000 bytes
so megabyte payloads don't balloon debug logs.
Wired into both the `queryApiSafeText` and `sendApiRequest` !ok
branches, which are the primary points where a non-thrown HTTP
error reaches a user. The success-path log includes the new
`requestedAt` timestamp too.
Added 5 new tests in `test/unit/utils/debug.test.mts` covering
requestedAt, cfRay (both casings), body passthrough, and body
truncation.
Existing debug-output shape preserved: callers that don't pass the
new fields (`responseHeaders`, `responseBody`, `requestedAt`) see
no change.
* 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.
* chore(debug): trim redundant comments in API debug logging
* chore(debug): restore __proto__: null on API debug payload
* chore(debug): sort ApiRequestDebugInfo properties alphabetically
* refactor(debug): route API failure logs through the error namespace
* fix(ci): bump pnpm to 11.0.0-rc.3 to unblock CI
CI was failing with `pnpm: 1: This: not found` (exit 127) during the
install step because @pnpm/exe@11.0.0-rc.2 ships a broken shell shim —
its pnpm binary begins with "This..." which the shell tries to execute
as a command. Affects main too, not just this PR.
- Bump `packageManager` from `pnpm@11.0.0-rc.2` to `pnpm@11.0.0-rc.3`.
- Bump `engines.pnpm` to `>=11.0.0-rc.3` to match.
- Regenerate `pnpm-lock.yaml` with rc.3 — the new lockfile no longer
pulls @pnpm/exe into packageManagerDependencies, which is why the
footprint shrinks. @pnpm/exe stays in the allowBuilds allowlist in
`pnpm-workspace.yaml` in case it's ever resolved transitively.
The socket-registry setup-and-install action (SHA a5923566c) already
installs pnpm rc.3, matching the upstream `_local-not-for-reuse-*`
workflows — so action pins do not need to change.1 parent de9daaf commit 35b9b9c
5 files changed
Lines changed: 235 additions & 261 deletions
File tree
- packages/cli
- src/utils
- socket
- test/unit/utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
33 | 45 | | |
34 | | - | |
35 | | - | |
36 | 46 | | |
37 | 47 | | |
| 48 | + | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
| |||
77 | 89 | | |
78 | 90 | | |
79 | 91 | | |
80 | | - | |
81 | | - | |
| 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 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
82 | 149 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 150 | + | |
| 151 | + | |
89 | 152 | | |
90 | 153 | | |
91 | 154 | | |
| |||
94 | 157 | | |
95 | 158 | | |
96 | 159 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
111 | 170 | | |
112 | | - | |
113 | 171 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 172 | + | |
128 | 173 | | |
129 | | - | |
| 174 | + | |
130 | 175 | | |
131 | 176 | | |
132 | 177 | | |
| |||
| 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 | | |
| |||
428 | 440 | | |
429 | 441 | | |
430 | 442 | | |
| 443 | + | |
431 | 444 | | |
432 | 445 | | |
433 | 446 | | |
| |||
443 | 456 | | |
444 | 457 | | |
445 | 458 | | |
| 459 | + | |
446 | 460 | | |
447 | 461 | | |
448 | 462 | | |
| |||
458 | 472 | | |
459 | 473 | | |
460 | 474 | | |
| 475 | + | |
461 | 476 | | |
462 | 477 | | |
463 | 478 | | |
| |||
475 | 490 | | |
476 | 491 | | |
477 | 492 | | |
478 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
479 | 496 | | |
480 | 497 | | |
481 | 498 | | |
482 | 499 | | |
| 500 | + | |
483 | 501 | | |
| 502 | + | |
| 503 | + | |
484 | 504 | | |
485 | 505 | | |
486 | 506 | | |
| |||
587 | 607 | | |
588 | 608 | | |
589 | 609 | | |
| 610 | + | |
590 | 611 | | |
591 | 612 | | |
592 | 613 | | |
| |||
614 | 635 | | |
615 | 636 | | |
616 | 637 | | |
| 638 | + | |
617 | 639 | | |
618 | 640 | | |
619 | 641 | | |
| |||
633 | 655 | | |
634 | 656 | | |
635 | 657 | | |
| 658 | + | |
636 | 659 | | |
637 | 660 | | |
638 | 661 | | |
| |||
653 | 676 | | |
654 | 677 | | |
655 | 678 | | |
656 | | - | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
657 | 682 | | |
658 | 683 | | |
659 | 684 | | |
660 | 685 | | |
| 686 | + | |
661 | 687 | | |
662 | 688 | | |
663 | 689 | | |
664 | 690 | | |
| 691 | + | |
| 692 | + | |
665 | 693 | | |
666 | 694 | | |
667 | 695 | | |
| |||
0 commit comments