Skip to content

Make API errors debuggable: preserve error-like values, decode body, attach request context#189

Draft
parthban-db wants to merge 1 commit into
parthban-db/stack/bugbash-bug2-apierror-codefrom
parthban-db/stack/bugbash-bug3-error-bodies
Draft

Make API errors debuggable: preserve error-like values, decode body, attach request context#189
parthban-db wants to merge 1 commit into
parthban-db/stack/bugbash-bug2-apierror-codefrom
parthban-db/stack/bugbash-bug3-error-bodies

Conversation

@parthban-db
Copy link
Copy Markdown
Contributor

@parthban-db parthban-db commented Jun 3, 2026

🥞 Stacked PR

Use this link to review incremental changes.


Summary

Makes API errors debuggable: ApiError now decodes the response body into its message and carries the failing request's method and URL, and toError preserves error-like values instead of collapsing them to Error: [object Object]. Pairs with universe PR #2025999, which regenerates the SDK output; the two must merge together.

Why

Today a non-JSON or non-conforming error response (proxy HTML, binary bodies) yields an empty ApiError message, and there is no indication of which request failed, so failures are opaque. This decodes the body so it is visible, prefixes the message with <method> <url>, and stops toError from discarding error-like objects that carry a string message.

What changed

  • ApiError.fromHttpError gains optional method/url params; new httpMethod/httpUrl getters expose them and the message is prefixed with "<method> <url>: ".
  • ApiError falls back to the decoded body as its message when the body is not JSON or fails schema validation, instead of an empty string.
  • toError (packages/core/src/ops/execute.ts) keeps the name and message of error-like objects.
  • Regenerates client.ts and utils.ts across all generated packages: executeHttpCall threads opts.request.method/url into fromHttpError, parseResponse wraps malformed-body parse failures in a real Error with a body snippet, and the client constructor validates host eagerly.
  • Decoding the body into the message and carrying request context intentionally diverges from the Go SDK's apierr.APIError.

Validated: build, typecheck, lint, and packages/core unit tests (apierror, execute) pass.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes.
If this is not necessary for your PR, please include the following in your PR description:
NO_CHANGELOG=true
and rerun the job.

@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug3-error-bodies branch from 6ef1457 to 259ed70 Compare June 4, 2026 11:02
@parthban-db parthban-db changed the base branch from main to parthban-db/stack/bugbash-bug2-apierror-code June 4, 2026 11:02
…attach request context

Fixes bug-bash finding #3 in the hand-written core, plus the regenerated SDK output from the paired universe generator PR.

toError in packages/core/src/ops/execute.ts now preserves the name and message of error-like objects (those with a string message) instead of collapsing them to Error: [object Object]. ApiError now decodes the response body into its message (so non-JSON, proxy HTML, and binary bodies are visible) and carries the failing request's method and URL: fromHttpError gains optional method/url params, new httpMethod/httpUrl getters expose them, and the message is prefixed with "<method> <url>: ". The generated executeHttpCall and sendAndCheckError call sites thread opts.request.method and opts.request.url through.

The regenerated client.ts and utils.ts across all packages come from the paired generator PR in the universe repo and must merge together with it. Note: decoding the body into the message and carrying request context intentionally diverges from the Go SDK's apierr.APIError.

Co-authored-by: Isaac
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug2-apierror-code branch from 8671804 to 357b416 Compare June 4, 2026 13:02
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug3-error-bodies branch from 259ed70 to 10e022f Compare June 4, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant