fix(client): surface nested error bodies and implement --debug#16
Merged
Conversation
The VKS API returns errors as {"error":{"message":...}} (nested object).
formatError only handled string fields, so users saw a bare
"API error (HTTP 400 Bad Request)" with no detail. Add a raw-body fallback.
Also wire up the previously-unused --debug flag to log request
method/URL/body and response status/body to stderr.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While running
grn vks generate-kubeconfig, a real server validation error was hidden behind a bareAPI error (HTTP 400 Bad Request). Two client deficiencies caused this:{"error":{"message":...}}(a nested object).formatErroronly extractederrorwhen it was a string, so the message was lost. Added a raw-body fallback so the server's message is always surfaced.--debugwas a no-op. Thedebugflag was stored but never used. Now logs request method/URL/body and response status/body to stderr.With the fix, the same call shows the actual reason:
Test Plan
go test ./internal/client/— newTestFormatErrorSurfacesNestedErrorObject,TestFormatErrorUsesPlainStringMessage, existing tests PASSgo vet ./...clean; build cleangrn vks generate-kubeconfig --debugnow prints request/response and the nested error message🤖 Generated with Claude Code