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

ehl-jf merged 2 commits into
masterfrom
JGC-437-error-handling

Conversation

@ehl-jf

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

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor


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 Resolved
@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
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
jfrog-cli 2.105.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What changed in v2.105.0

> Auto-generated from 6 repositories · 2026-05-28  
> Comparing `v2.104.1` → `v2.105.0`

> ℹ️  No changes in: gofrog

### ✨ New Features

- **[build-info-go]** added nix package manager support [#378](jfrog/build-info-go#378) (@reshmifrog)
- **[jfrog-cli]** add nix package manager support [#3471](jfrog/jfrog-cli#3471) (@reshmifrog)
- **[jfrog-cli-artifactory]** RTECO-1266 - Implement ai plugins publish command [#454](jfrog/jfrog-cli-artifactory#454) (@udaykb2)
- **[jfrog-cli-artifactory]** add nix package manager [#442](jfrog/jfrog-cli-artifactory#442) (@reshmifrog)
- **[jfrog-cli-core]** RTECO-1266 - Add Subcommand to command [#1560](jfrog/jfrog-cli-core#1560) (@udaykb2)
- **[jfrog-cli-security]** XRAY-140488 - Implement graceful dotnet restore error for all dotnet … [#752](jfrog/jfrog-cli-security#752) (@gauriy-tech)

### 🐛 Bug Fixes

- **[jfrog-cli]** RTECO-1368 - Fix metrics collection for agent detection and interactive context fields [#3518](jfrog/jfrog-cli#3518) (@fluxxBot)
- **[jfrog-cli-artifactory]** Fix: Return error when jfrog server is not configured [#459](jfrog/jfrog-cli-artifactory#459) (@udaykb2)
- **[jfrog-cli-core]** RTECO-1368 - Fix metrics collection for agent detection and interactive context fields [#1566](jfrog/jfrog-cli-core#1566) (@fluxxBot)
- **[jfrog-cli-security]** Fix nil dereference issue regarding Applicability Scan results [#755](jfrog/jfrog-cli-security#755) (@eranturgeman)
- **[jfrog-cli-security]** Populate project key to GetConfigProfileByUrl [#763](jfrog/jfrog-cli-security#763) (@eranturgeman)
- **[jfrog-cli-security]** Adjust rtRepository path when in project context [#764](jfrog/jfrog-cli-security#764) (@eranturgeman)

### 🔧 Internal Changes

- **[jfrog-cli-security]** Update AnalyzerManager default version to 1.34.1 [#754](jfrog/jfrog-cli-security#754) (@attiasas)
- **[jfrog-cli-security]** Update dependencies for 1.29.2 [#765](jfrog/jfrog-cli-security#765) (@eranturgeman)

### 📦 Other Changes

- **[jfrog-cli]** Enable JSON error output for commands with HTTP requests [#3493](jfrog/jfrog-cli#3493) (@ehl-jf)
- **[jfrog-cli]** Make jf uv command publicly available [#3511](jfrog/jfrog-cli#3511) (@agrasth)
- **[jfrog-cli-artifactory]** RTECO-1266 - Rename ai plugins to agent plugins [#456](jfrog/jfrog-cli-artifactory#456) (@udaykb2)
- **[jfrog-client-go]** Expose full HTTP response in case of error [#1345](jfrog/jfrog-client-go#1345) (@ehl-jf)

---

### 📊 Summary

| Repository | Changes |
|---|---|
| [jfrog-cli-security](https://github.com/jfrog/jfrog-cli-security) | 6 |
| [jfrog-cli](https://github.com/jfrog/jfrog-cli) | 4 |
| [jfrog-cli-artifactory](https://github.com/jfrog/jfrog-cli-artifactory) | 4 |
| [jfrog-cli-core](https://github.com/jfrog/jfrog-cli-core) | 2 |
| [build-info-go](https://github.com/jfrog/build-info-go) | 1 |
| [jfrog-client-go](https://github.com/jfrog/jfrog-client-go) | 1 |
| **Total** | **18** |

### 🔗 Module Version Changes

| Module | From | To |
|---|---|---|
| [build-info-go](https://github.com/jfrog/build-info-go) | `v1.13.1-0.20260521104402-1e35b9b5b0c6` | `v1.13.1-0.20260526201157-3dd942bd9e1f` |
| [jfrog-cli-artifactory](https://github.com/jfrog/jfrog-cli-artifactory) | `v0.8.1-0.20260520131142-ef80a14dd499` | `v0.8.1-0.20260527043943-fdf755c4f4c2` |
| [jfrog-cli-core](https://github.com/jfrog/jfrog-cli-core) | `v2.60.1-0.20260520130103-75be6a23c54b` | `v2.60.1-0.20260528061115-b41c87af0194` |
| [jfrog-cli-security](https://github.com/jfrog/jfrog-cli-security) | `v1.29.0` | `v1.29.2` |
| [jfrog-client-go](https://github.com/jfrog/jfrog-client-go) | `v1.55.1-0.20260521115926-32f082854b39` | `v1.55.1-0.20260527095031-a0b759bcd723` |
</pre>
  <p>View the full release notes at <a href="https://github.com/jfrog/jfrog-cli/releases/tag/v2.105.0">https://github.com/jfrog/jfrog-cli/releases/tag/v2.105.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!8877

This branch had an error being deployed

1 failed deployment
frogbot — aa089ab5 Deployed May 22, 2026 by ehl-jf via scan-pull-request #4297
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