Skip to content

Commit c2c2d43

Browse files
authored
chore(triage-action): Fix JSON parsing (#19471)
The file is a single pretty-printed JSON array, `JSON.stringify(messages, null, 2)` ([source code](https://github.com/anthropics/claude-code-action/blob/edd85d61533cbba7b57ed0ca4af1750b1fdfd3c4/base-action/src/run-claude-sdk.ts#L183-L189)), not NDJSON. This script change (treating the parsed root as a list and collecting objects with type === "result") reads it correctly. This is the the current error output: ``` Traceback (most recent call last): File "/home/runner/work/sentry-javascript/sentry-javascript/.claude/skills/triage-issue/scripts/write_job_summary.py", line 109, in <module> sys.exit(main()) ^^^^^^ File "/home/runner/work/sentry-javascript/sentry-javascript/.claude/skills/triage-issue/scripts/write_job_summary.py", line 55, in main if obj.get("type") == "result": ^^^^^^^ ``` Closes #19472 (added automatically)
1 parent 737bd87 commit c2c2d43

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

.claude/skills/triage-issue/scripts/write_job_summary.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
Usage:
77
python3 write_job_summary.py <path-to-claude-execution-output.json>
88
9-
Handles single JSON object or NDJSON (one JSON object per line).
10-
Uses the last object with type "result" when multiple are present.
9+
The execution file is written by anthropics/claude-code-action as a single
10+
JSON array of messages (JSON.stringify(messages, null, 2)) at
11+
$RUNNER_TEMP/claude-execution-output.json. We also support NDJSON (one
12+
object per line). Uses the last object with type "result" for metrics.
1113
1214
Job summary has a ~1MB limit; raw JSON is truncated if needed to avoid job abort.
1315
"""
@@ -52,17 +54,25 @@ def main() -> int:
5254
continue
5355
try:
5456
obj = json.loads(line)
55-
if obj.get("type") == "result":
57+
if isinstance(obj, dict) and obj.get("type") == "result":
5658
results.append(obj)
59+
elif isinstance(obj, list):
60+
for item in obj:
61+
if isinstance(item, dict) and item.get("type") == "result":
62+
results.append(item)
5763
except json.JSONDecodeError:
5864
continue
5965

6066
if not results:
61-
# Try parsing whole content as single JSON
67+
# Try parsing whole content as single JSON (object or array)
6268
try:
6369
obj = json.loads(content)
64-
if obj.get("type") == "result":
70+
if isinstance(obj, dict) and obj.get("type") == "result":
6571
results = [obj]
72+
elif isinstance(obj, list):
73+
for item in obj:
74+
if isinstance(item, dict) and item.get("type") == "result":
75+
results.append(item)
6676
except json.JSONDecodeError:
6777
pass
6878

0 commit comments

Comments
 (0)