Conversation
checkErr now resolves every error to a StructuredError (an explicit implementation, or a genericStructuredError synthesized from the status-code table) and renders Title, Reason, Status and Next step as separate lines, mirroring the same four fields into the JSON error envelope additively (detail is unchanged). FlagValidationError implements the interface for its JSON output while keeping its own richer text block. Adds an error-code table (error_codes.go) for common API status codes (400/401/403/404/409/422/429/5xx), each with a canned reason and a "run <command>" next step so Style.Hint bolds the whole suggestion. Names the two exit codes doctl has always used (exitGeneralError=1, exitUsageError=255) instead of magic numbers, and routes the config-read failure through checkErr instead of a raw log.Fatalln so it gets the same formatting and a controlled exit code. Also fixes a pre-existing bug in auth.go's writeConfig(), which referenced an out-of-scope `context` identifier and could not compile; it's now a parameter from its one call site.
SSharma-10
reviewed
Sep 15, 2026
Comment on lines
346
to
+347
| notice("Now using context [%s] by default", context) | ||
| return writeConfig() | ||
| return writeConfig(context) |
Contributor
There was a problem hiding this comment.
We are printing the success message twice: notice above and fmt.Printf in writeConfig L362
Contributor
|
Build looks good now, but the auth switch is still broken. Locally,
Looks like |
Contributor
|
Tried this locally: doctl compute droplet get 999999999 Text only shows "Not Found" + the canned reason, the actual API message only shows up in json |
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
checkErrnow resolves every error to aStructuredError(an explicit implementation, or agenericStructuredErrorsynthesized from a new status-code table) and renders Title → Reason → Status → Next step as separate lines, mirroring the same four fields into the JSON error envelope additively (detailunchanged for existing consumers).commands/error_codes.go: canned reason + arun <command>next step for common API status codes (400/401/403/404/409/422/429/5xx), soStyle.Hintbolds the whole suggestion consistently.FlagValidationErrorimplements the new interface for its JSON output while keeping its own richer per-flag text block untouched.exitGeneralError = 1,exitUsageError = 255) instead of magic numbers, and routes the config-read failure throughcheckErrinstead of a rawlog.Fatalln, so it gets consistent formatting and a controlled exit code.auth.go'swriteConfig(), which referenced an out-of-scopecontextidentifier; it's now a parameter from its one call site.Test plan
go build ./cmd/doctlsucceedsgo vet ./commands/... ./internal/...cleango test ./commands/...— existingcheckErr/FlagValidationErrortests pass unchanged (one pre-existing, unrelated failure:TestRenderWelcomeUsesASCIIGlyphsWhenRequired, confirmed to fail identically without these changes)🤖 Generated with Claude Code