Skip to content

Enable JSON error output for commands with HTTP requests#3493

Merged
ehl-jf merged 2 commits into
masterfrom
JGC-437-error-handling
May 22, 2026
Merged

Enable JSON error output for commands with HTTP requests#3493
ehl-jf merged 2 commits into
masterfrom
JGC-437-error-handling

Conversation

@ehl-jf
Copy link
Copy Markdown
Contributor

@ehl-jf ehl-jf commented May 18, 2026

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:

Mechanism Example
Environment variable JFROG_CLI_ERROR_OUTPUT_FORMAT=json jf rt ping ...
--format=json auto-promote jf 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)

Stream Contents
stdout parseable JSON: {status_code, status, body} — body is a nested object when the server returned JSON
stderr log lines only ([Info]/[Warn]/Trace ID), unchanged from today
exit 1

Makes jf <cmd> --format=json 1>out.json 2>err.log work cleanly: jq . out.json parses, err.log is for humans.

Coverage

  • All commands routing through jfrog-client-go's CheckResponseStatus* (i.e. the standard HTTP error path on every JFrog service).
  • OIDC token exchange (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.
  • Transport errors (connection refused, TLS) intentionally fall through to the existing text path — there's no HTTP response to wrap.

Companion PR

Depends on jfrog/jfrog-client-go#1345, which exposes the typed HttpResponseError this 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) and general/api/cli_test.go (JSON-mode emits structured stdout, success path unchanged, default mode still dumps body).


  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • The pull request is targeting the master branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
✅ (ehl-jf)[https://github.com/ehl-jf]
@actions-user
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@ehl-jf ehl-jf force-pushed the JGC-437-error-handling branch from a6b3771 to 4dd94e3 Compare May 18, 2026 07:16
@ehl-jf ehl-jf added the safe to test Approve running integration tests on a pull request label May 18, 2026
@ehl-jf ehl-jf force-pushed the JGC-437-error-handling branch from 4dd94e3 to db576f7 Compare May 18, 2026 09:07
@ehl-jf ehl-jf added safe to test Approve running integration tests on a pull request and removed safe to test Approve running integration tests on a pull request labels May 18, 2026
Comment thread utils/cliutils/errorformat.go Outdated
@ehl-jf ehl-jf force-pushed the JGC-437-error-handling branch from db576f7 to 6f50b4d Compare May 22, 2026 07:38
@ehl-jf ehl-jf added safe to test Approve running integration tests on a pull request and removed safe to test Approve running integration tests on a pull request labels 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).
@ehl-jf ehl-jf added safe to test Approve running integration tests on a pull request and removed safe to test Approve running integration tests on a pull request labels May 22, 2026
@ehl-jf ehl-jf enabled auto-merge (squash) May 22, 2026 08:04
@ehl-jf ehl-jf merged commit 2d1c013 into master May 22, 2026
86 of 88 checks passed
@ehl-jf ehl-jf deleted the JGC-437-error-handling branch May 22, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Approve running integration tests on a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants