Skip to content

Enable JSON error output for commands with HTTP requests#3493

Open
ehl-jf wants to merge 1 commit into
masterfrom
JGC-437-error-handling
Open

Enable JSON error output for commands with HTTP requests#3493
ehl-jf wants to merge 1 commit 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


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you 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


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
// 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' {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test case for a long error code, more than 9 digits?

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.

3 participants