{"record":{"id":"4952872472037442","repo":"affaan-m/ECC","slug":"claude-p-failed-result-stderr-495287","errorCode":null,"errorMessage":"claude -p failed: {result.stderr}","messagePattern":"claude -p failed: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"skills/skill-comply/scripts/spec_generator.py","lineNumber":51,"sourceCode":"    for attempt in range(max_retries + 1):\n        prompt = base_prompt\n        if attempt > 0 and last_error is not None:\n            prompt += (\n                f\"\\n\\nPREVIOUS ATTEMPT FAILED with YAML parse error:\\n\"\n                f\"{last_error}\\n\\n\"\n                f\"Please fix the YAML. Remember to quote all string values \"\n                f\"that contain colons, e.g.: description: \\\"Use type: description format\\\"\"\n            )\n\n        result = subprocess.run(\n            [\"claude\", \"-p\", prompt, \"--model\", model, \"--output-format\", \"text\"],\n            capture_output=True,\n            text=True,\n            timeout=120,\n        )\n\n        if result.returncode != 0:\n            raise RuntimeError(f\"claude -p failed: {result.stderr}\")\n\n        raw_yaml = extract_yaml(result.stdout)\n\n        tmp_path = None\n        with tempfile.NamedTemporaryFile(\n            mode=\"w\", suffix=\".yaml\", delete=False,\n        ) as f:\n            f.write(raw_yaml)\n            tmp_path = Path(f.name)\n\n        try:\n            return parse_spec(tmp_path)\n        except (yaml.YAMLError, KeyError, TypeError) as e:\n            last_error = e\n            if attempt == max_retries:\n                raise\n        finally:\n            if tmp_path is not None:","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/skills/skill-comply/scripts/spec_generator.py#L33-L69","documentation":"generate_spec() calls `claude -p` to produce a compliance spec as YAML. If the subprocess returns non-zero on any attempt (including retries), the loop aborts immediately with the raw stderr. This short-circuits the retry logic, which only retries YAML parse errors — not subprocess failures.","triggerScenarios":"claude CLI missing; ANTHROPIC_API_KEY missing or revoked; network unreachable; subprocess exceeded the 120s timeout (raised as subprocess.TimeoutExpired, a different exception); the model returned an error response that caused non-zero exit.","commonSituations":"CI without auth; an expired token mid-run; a too-large skill_path that overflowed the context window and made the API return an error.","solutions":["Inspect stderr in the message — it identifies the failure mode.","Verify `claude -p ping --model haiku` works in the same shell.","Export ANTHROPIC_API_KEY or run `claude login`.","Note that retries only cover YAML parse errors, so a transient API failure will not auto-retry — wrap the call and retry at the orchestrator level if needed."],"exampleFix":"# before\nspec = generate_spec(skill_path, model='haiku')\n\n# after\nimport time\nfor attempt in range(3):\n    try:\n        spec = generate_spec(skill_path, model='haiku')\n        break\n    except RuntimeError as e:\n        if attempt == 2:\n            raise\n        time.sleep(2 ** attempt)","handlingStrategy":"retry","validationCode":"import os, shutil\n\ndef can_generate_spec() -> bool:\n    return (\n        shutil.which('claude') is not None\n        and bool(os.environ.get('ANTHROPIC_API_KEY'))\n    )","typeGuard":null,"tryCatchPattern":"from scripts.spec_generator import generate_spec\nimport time\nfor attempt in range(3):\n    try:\n        spec = generate_spec(skill_path, model='haiku')\n        break\n    except RuntimeError as e:\n        if attempt == 2:\n            raise\n        time.sleep(2 ** attempt)","preventionTips":["Note that generate_spec only retries on YAML parse errors, not on subprocess failures — wrap with your own retry for transient API errors.","Pre-flight the claude CLI and ANTHROPIC_API_KEY before the run.","If the skill file is very large, summarize it before passing to generate_spec to avoid context overflow."],"tags":["subprocess","claude-cli","skill-comply","spec-generator"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}