{"record":{"id":"e2e1fd53eb36bb79","repo":"Hmbown/CodeWhale","slug":"codewhale-stream-json-line-line-number-was-not-valid-json","errorCode":null,"errorMessage":"Codewhale stream-json line {line_number} was not valid JSON","messagePattern":"Codewhale stream-json line (.+?) was not valid JSON","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"integrations/verifiers-codewhale/codewhale_harness/harness.py","lineNumber":355,"sourceCode":"done\n(cd \"$install_dir/bin\" && sha256sum codewhale codew codewhale-tui > .sha256.tmp)\nmv -f \"$install_dir/bin/.sha256.tmp\" \"$install_dir/bin/.sha256\"\nprintf '%s' \"$version\" > \"$install_dir/bin/.version.tmp\"\nmv -f \"$install_dir/bin/.version.tmp\" \"$install_dir/bin/.version\"\n\"\"\"\n\n\ndef _parse_stream_receipt(stdout: str) -> dict[str, Any]:\n    counts: Counter[str] = Counter()\n    terminal: dict[str, Any] | None = None\n    ordered_types: list[str] = []\n    for line_number, line in enumerate(stdout.splitlines(), start=1):\n        if not line.strip():\n            continue\n        try:\n            event = json.loads(line)\n        except json.JSONDecodeError as error:\n            raise RuntimeError(\n                f\"Codewhale stream-json line {line_number} was not valid JSON\"\n            ) from error\n        if not isinstance(event, dict):\n            raise RuntimeError(\n                f\"Codewhale stream-json line {line_number} was not an object\"\n            )\n        if event.get(\"schema\") != STREAM_SCHEMA or event.get(\n            \"schema_version\"\n        ) != STREAM_SCHEMA_VERSION:\n            raise RuntimeError(\"Codewhale stream-json schema did not match v0.9.1\")\n        event_type = event.get(\"type\")\n        if event_type not in _EVENT_TYPES:\n            raise RuntimeError(\"Codewhale stream-json contained an unknown event type\")\n        counts[event_type] += 1\n        ordered_types.append(event_type)\n        if event_type == \"metadata\":\n            if terminal is not None:\n                raise RuntimeError(\"Codewhale emitted more than one terminal metadata receipt\")","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/integrations/verifiers-codewhale/codewhale_harness/harness.py#L337-L373","documentation":"Codewhale emits its run log as newline-delimited JSON (stream-json) on stdout, and every non-blank line must parse as JSON. This RuntimeError, chained from json.JSONDecodeError, means line N of the program's stdout was not valid JSON. The harness throws it immediately because partial/corrupt stream output means the receipt cannot be trusted.","triggerScenarios":"_parse_stream_receipt iterated result.stdout after a zero exit code and json.loads failed on a line — e.g. human-readable log text, progress bars, warnings, or a crash message interleaved with the stream.","commonSituations":"A wrapper binary or shell profile printing banners to stdout; a pre-release binary writing plain-text logs; NO_COLOR/telemetry settings not honored; output corruption from pipes or encoding issues.","solutions":["Capture and inspect the raw stdout around the reported line_number to see what was printed","Remove wrappers/shell rc files that echo text when the binary runs (check binary_path)","Upgrade or pin Codewhale to the 0.9.1 release whose --output-format stream-json is clean","Ensure NO_COLOR=1 and --telemetry false reach the binary so no decorated lines are emitted","If you control the emitter, direct human logs to stderr and keep stdout strictly NDJSON"],"exampleFix":"// before (emitting binary)\nprintf(\"starting run...\\n\");  // stdout\n// after\nfprintf(stderr, \"starting run...\\n\");","handlingStrategy":"try-catch","validationCode":"import json\ndef stdout_is_ndjson(stdout: str) -> bool:\n    return all(\n        (not line.strip()) or _is_json(line)\n        for line in stdout.splitlines()\n    )\ndef _is_json(line: str) -> bool:\n    try:\n        json.loads(line); return True\n    except json.JSONDecodeError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    result = await harness.launch(ctx, trace, runtime, endpoint, secret, mcp_urls)\nexcept RuntimeError as e:\n    if \"was not valid JSON\" in str(e):\n        logger.error(\"non-NDJSON on stdout; check wrappers and stderr discipline\")\n    raise","preventionTips":["Keep stdout strictly newline-delimited JSON; all human logs go to stderr","Test the binary in a clean shell without rc-file banners","Pin the release; verify --output-format stream-json is honored","Run the binary manually before rollouts and pipe stdout through a JSON-line linter"],"tags":["json","parsing","stream"],"backgroundTag":"json-parse-error","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}