Enable JSON error output for commands with HTTP requests#3493
Merged
Conversation
Contributor
|
I have read the CLA Document and I hereby sign the CLA 1 out of 2 committers have signed the CLA. |
a6b3771 to
4dd94e3
Compare
4dd94e3 to
db576f7
Compare
vitaliil-jfrog
approved these changes
May 18, 2026
db576f7 to
6f50b4d
Compare
christophermiJfrog
approved these changes
May 22, 2026
The digit-count cap in parseLegacyHTTPResponseError previously truncated 10+ digit inputs to their first 9 digits, producing a JSON status_code the server never sent. Change the loop to count all leading digits and return nil when the count exceeds 9, so the caller falls back to the text path for clearly malformed inputs. Adds TestLegacyHTTPErrorCodeDigitLimits with four subtests covering the upper boundary (9 digits accepted), one digit over the cap (10 digits rejected), a far-past-the-cap input (20 digits rejected), and an end-to-end check that HandleHTTPErrorAsJSON emits no JSON for the too-long case (text-path fallthrough).
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 ./....