fix(cli): keep TUS upload failure detail instead of "unknown error"

Merged
PO
3mo ago
+18-3

Summary

  • A failed capgo bundle upload with an empty response body reached the user as the literal string unknown error — the HTTP status, request URL, and raw body were all dropped. This minted a fresh error tracking issue per occurrence and left both the user and the team unable to act.
  • Root cause: the uploadTUS onError handler ran JSON.parse outside any try/catch and rejected a bare string, so an empty body collapsed to unknown error and a non-JSON proxy page (HTML 502/504) threw a SyntaxError inside the tus callback.
  • Fix: port the handler shape that already works in cli/src/build/request.ts — wrap the parse in a try/catch that falls back to the raw body then the tus error message, add the HTTP status and request URL to the message, and reject a real Error.
CaseBeforeAfter
Empty bodyunknown errorTUS upload failed (status 502, url …): <body or tus message>
Non-JSON body (HTML 502/504)SyntaxError thrown in callbackraw body surfaced in a rejected Error
JSON body (invalid_apikey, app_not_found, …)real cause (unchanged)real cause (unchanged)

Test plan

  • No behaviour change for the JSON-body path (invalid_apikey, app_not_found, insufficient_permissions) — those still surface their real cause.
  • Empty-body and non-JSON-body failures now reject a real Error carrying the status, URL, and body instead of unknown error.

Screenshots

Checklist

  • My code follows the code style of this project and passes
    bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation
    accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce
    my tests

Agent context

  • Complementary to open PR #2932, which also touches cli/src/utils.ts but fixes the neighbouring $exception_fingerprint problem in findSavedKey; it leaves the uploadTUS handler alone, so the two do not conflict.

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.