{"record":{"id":"ee3e73fc670c6a5a","repo":"affaan-m/ECC","slug":"claude-p-failed-result-stderr","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/scenario_generator.py","lineNumber":51,"sourceCode":"    Calls claude -p with the scenario_generator prompt, parses YAML output.\n    \"\"\"\n    skill_content = skill_path.read_text()\n    prompt_template = (PROMPTS_DIR / \"scenario_generator.md\").read_text()\n    prompt = (\n        prompt_template\n        .replace(\"{skill_content}\", skill_content)\n        .replace(\"{spec_yaml}\", spec_yaml)\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    if not result.stdout.strip():\n        raise RuntimeError(\"claude -p returned empty output\")\n\n    raw_yaml = extract_yaml(result.stdout)\n    parsed = yaml.safe_load(raw_yaml)\n\n    scenarios: list[Scenario] = []\n    for s in parsed[\"scenarios\"]:\n        scenarios.append(Scenario(\n            id=s[\"id\"],\n            level=s[\"level\"],\n            level_name=s[\"level_name\"],\n            description=s[\"description\"],\n            prompt=s[\"prompt\"].strip(),\n            setup_commands=tuple(s.get(\"setup_commands\", [])),\n        ))\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/skills/skill-comply/scripts/scenario_generator.py#L33-L69","documentation":"generate_scenarios() invokes `claude -p` to produce scenario YAML. If the subprocess returns non-zero, the run is aborted with the raw stderr. Unlike runner.run_scenario, this path does not surface stdout or distinguish max_turns — only stderr is captured in the message.","triggerScenarios":"claude CLI not installed or not on PATH; API key missing/invalid; network failure to the model endpoint; the model call exceeded the 120s timeout (subprocess.TimeoutExpired, raised separately); model rejected the assembled prompt.","commonSituations":"CI image without the claude binary; an expired token; a scenario_generator prompt template that grew too large for the model context window.","solutions":["Read stderr in the message — it usually names the cause directly.","Confirm `claude -p 'ping' --model haiku` works in the same shell and environment.","Ensure ANTHROPIC_API_KEY is exported or `claude login` has been run.","If stderr is empty, raise the timeout above 120s or shorten the skill/spec input fed into the prompt."],"exampleFix":"# before\nscenarios = generate_scenarios(skill_path, spec_yaml, model='haiku')\n\n# after\ntry:\n    scenarios = generate_scenarios(skill_path, spec_yaml, model='haiku')\nexcept RuntimeError as e:\n    raise SystemExit(f'scenario generation failed; check claude CLI/auth: {e}') from e","handlingStrategy":"try-catch","validationCode":"import os, shutil\n\ndef can_generate_scenarios() -> 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.scenario_generator import generate_scenarios\ntry:\n    scenarios = generate_scenarios(skill_path, spec_yaml, model='haiku')\nexcept RuntimeError as e:\n    raise SystemExit(f'scenario generation failed (check claude CLI/auth): {e}') from e","preventionTips":["Pre-flight: run `claude -p ping --model haiku` in CI before invoking generate_scenarios.","Keep the scenario_generator prompt template under the model's context budget.","Surface stderr to logs verbatim so failures are diagnosable without a re-run."],"tags":["subprocess","claude-cli","skill-comply","scenario-generator"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}