Skip to content

Commit 4649508

Browse files
yeldarbyclaude
andcommitted
fix(cli): parse JSON error strings to avoid double-encoding in --json mode
When an API error message is itself a JSON string, output_error now parses it so the error field contains a proper object instead of a stringified JSON string. This lets agents parse errors with a single json.loads() call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent edacf90 commit 4649508

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

roboflow/cli/_output.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ def output_error(
5656
Process exit code. Convention: 1 = general, 2 = auth, 3 = not found.
5757
"""
5858
if getattr(args, "json", False):
59-
payload: dict[str, Any] = {"error": message}
59+
# If message is a JSON string (e.g. from an API response), parse it
60+
# so the error field is a proper object, not a double-encoded string.
61+
error_value: Any = message
62+
try:
63+
parsed = json.loads(message)
64+
if isinstance(parsed, dict):
65+
error_value = parsed
66+
except (json.JSONDecodeError, TypeError):
67+
pass
68+
payload: dict[str, Any] = {"error": error_value}
6069
if hint:
6170
payload["hint"] = hint
6271
print(json.dumps(payload), file=sys.stderr)

0 commit comments

Comments
 (0)