Surface failing request IDs in CLI errors
Merged
RO
5mo ago+231+231+012345678901234567890123456789-4-4-0123456789
Summary
- surface failing SDK request ids in CLI error output
- include
request_idin JSON error metadata and render it for human-facing formats - make raw
basecamp api post/put/deleteerror handling use the same SDK->CLI conversion path asapi get
SDK dependency
- Requires the SDK change from basecamp/basecamp-sdk#277 (carries
X-Request-Idonbasecamp.Error), which is now inmain— this branch is rebased on top of it and builds against SDKv0.7.4-0.20260629111348-cc8e9772e729.
Problem
The Basecamp API already emits X-Request-Id, and the SDK now preserves that value consistently on basecamp.Error for both generated-service calls and raw client calls.
Before this PR, the CLI still dropped that information:
convertSDKError()copied SDK code/message/hint/status fields but discarded the underlying SDK error- JSON error envelopes had nowhere to expose the request id
- styled/plain/markdown error rendering did not show it
basecamp api post/put/deletereturned raw SDK errors instead of using the same conversion path asapi get
That meant users still could not see the failing request id when the CLI hit an API error, even though the SDK had it available.
What changed
- taught
internal/output.AsError()to convert raw*basecamp.Errorvalues into CLI errors while preserving the SDK error as the cause - added
output.RequestID(err)to recover the SDK request id from the error chain - included
meta.request_idin JSON error responses when present - rendered
Request ID: ...in styled, plain-text, and markdown error output - updated
convertSDKError()to retain the wrapped SDK error as the cause - made
basecamp api post,put, anddeleteuseconvertSDKError()just likeapi get - added tests for request-id JSON metadata, human rendering, and SDK->CLI conversion
Resulting UX
JSON errors now look like:
{
"ok": false,
"error": "server error",
"code": "api_error",
"meta": {
"request_id": "req-cli-123"
}
}
Human-facing error output now includes a dedicated request-id line, e.g.:
Error: server error
Request ID: req-cli-123
Testing
go test ./internal/output -run 'TestWriterErrIncludesRequestIDMeta|TestWriterStyledErrorIncludesRequestID|TestWriterMarkdownErrorIncludesRequestID|TestWriterErr|TestWriterStyledErrorWithHint'
go test ./internal/commands -run 'TestConvertSDKErrorPreservesRequestID|TestParsePath|TestAPIPathArgs'
Summary by cubic
Show failing Basecamp API request IDs in CLI errors for easier debugging and support. Adds the request ID to JSON error metadata and all human-facing formats with sanitization and wrapping.
-
Bug Fixes
- Handle raw or wrapped
*basecamp.Errorinoutput.AsError(); preserve it as the cause and keep request context. - Include
meta.request_idin JSON error responses usingoutput.RequestID(err). - Render “Request ID: …” in styled, plain text, and markdown outputs; sanitize control/ANSI chars, correctly escape markdown (including single backslashes), and wrap long IDs.
- Route
basecamp api post/put/deletethroughconvertSDKError()likeapi get. - Add tests for JSON metadata, human rendering, sanitization, markdown backslash escaping, and SDK→CLI conversion.
- Handle raw or wrapped
-
Dependencies
- Requires
basecamp-sdkupdate that carriesX-Request-Idinbasecamp.Error(basecamp/basecamp-sdk#277).
- Requires