Enable JSON error output for commands with HTTP requests#3493
Open
ehl-jf wants to merge 1 commit into
Open
Conversation
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
a6b3771 to
4dd94e3
Compare
4dd94e3 to
db576f7
Compare
vitaliil-jfrog
approved these changes
May 18, 2026
| // Cap the digit count so Atoi cannot overflow on malformed input — real | ||
| // HTTP statuses are 3 digits; 9 leaves plenty of headroom under int32. | ||
| codeEnd := 0 | ||
| for codeEnd < len(statusLine) && codeEnd < 9 && statusLine[codeEnd] >= '0' && statusLine[codeEnd] <= '9' { |
Collaborator
There was a problem hiding this comment.
Do we have a test case for a long error code, more than 9 digits?
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
Adds opt-in JSON output for HTTP error responses across the entire CLI. When enabled, any command that hits the platform — Artifactory, Access, Xray, Pipelines, OIDC token exchange — emits a structured JSON object on stdout (the data channel) instead of human-readable text on stderr. Default behavior is unchanged; this is purely additive.
How to use
Two equivalent triggers:
JFROG_CLI_ERROR_OUTPUT_FORMAT=json jf rt ping ...--format=jsonauto-promotejf rt ping --format=json ...If both are set, the env var wins. Any value other than
json(or unset) keeps the current text behavior.Channel contract (JSON mode)
{status_code, status, body}— body is a nested object when the server returned JSON[Info]/[Warn]/Trace ID), unchanged from todayMakes
jf <cmd> --format=json 1>out.json 2>err.logwork cleanly:jq . out.jsonparses,err.logis for humans.Coverage
jfrog-client-go'sCheckResponseStatus*(i.e. the standard HTTP error path on every JFrog service).jf eot) end-to-end.jf api: in JSON mode, the structured error replaces the body-on-stdout dump; in default mode, curl-like behavior is preserved.Companion PR
Depends on jfrog/jfrog-client-go#1345, which exposes the typed
HttpResponseErrorthis PR consumes. go.mod is pinned to that branch's pseudo-version; bump to a released version once #1345 merges.Tests
Unit tests in
utils/cliutils/errorformat_test.go(env var precedence, flag auto-promote variants, false-positive guards, legacy-text fallback) andgeneral/api/cli_test.go(JSON-mode emits structured stdout, success path unchanged, default mode still dumps body).masterbranch.go vet ./....go fmt ./....