{"record":{"id":"2c3cc360f7a92085","repo":"bmad-code-org/BMAD-METHOD","slug":"corrupt-existing-generation-destination-error","errorCode":null,"errorMessage":"corrupt existing generation {destination}: {error}","messagePattern":"corrupt existing generation (.+?): (.+?)","errorType":"exception","errorClass":"RenderError","httpStatus":null,"severity":"critical","filePath":"src/scripts/render_skill.py","lineNumber":275,"sourceCode":"            raise RenderError(f\"unsupported render token: {token}\")\n        target = snapshot.group(1)\n        if target not in source_names:\n            raise RenderError(f\"snapshot reference targets undeclared source: {target}\")\n        return str(destination / target)\n\n    rendered: dict[str, str] = {}\n    for name, content in sources.items():\n        # Inserted paths and customization prose are never scanned as source tokens.\n        rendered[name] = token_pattern.sub(replace, content)\n    return rendered\n\n\ndef _verify_existing(destination: Path, manifest: dict[str, Any]) -> None:\n    manifest_path = destination / \"manifest.json\"\n    try:\n        existing = json.loads(manifest_path.read_text(encoding=\"utf-8\"))\n    except (OSError, UnicodeError, json.JSONDecodeError) as error:\n        raise RenderError(f\"corrupt existing generation {destination}: {error}\") from error\n    if existing != manifest:\n        raise RenderError(f\"generation collision or corruption at {destination}\")\n    expected_files = set(manifest[\"outputs\"]) | {\"manifest.json\"}\n    actual_files = {\n        path.relative_to(destination).as_posix()\n        for path in destination.rglob(\"*\")\n        if path.is_file()\n    }\n    if actual_files != expected_files:\n        raise RenderError(f\"generation contains unexpected or missing files: {destination}\")\n    for name, expected_hash in manifest[\"outputs\"].items():\n        try:\n            actual_hash = _hash_bytes((destination / name).read_bytes())\n        except OSError as error:\n            raise RenderError(f\"failed to verify {destination / name}: {error}\") from error\n        if actual_hash != expected_hash:\n            raise RenderError(f\"generation output hash mismatch: {destination / name}\")\n","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/bmad-code-org/BMAD-METHOD/blob/b70486b9bdcb0a404d329e2a763b57964e7f1360/src/scripts/render_skill.py#L257-L293","documentation":"When the destination generation directory already exists, _verify_existing reads manifest.json. If that file is missing/unreadable (OSError), not valid UTF-8 (UnicodeError), or not valid JSON (JSONDecodeError), the generation is treated as corrupt and rendering aborts rather than silently overwriting.","triggerScenarios":"Re-running render into the same destination hash directory where manifest.json was deleted, truncated, or contains invalid JSON (e.g. hand-edited and broken).","commonSituations":"Manual editing/deletion of generated directories; partial writes from a previously crashed run; hand-editing the manifest.","solutions":["Delete the corrupt generation directory and re-run render to regenerate it cleanly.","If generations are committed to VCS, restore manifest.json from version control.","Avoid manually editing files inside generated output directories."],"exampleFix":"# before: manifest.json missing or corrupt\n# after\nrm -rf _bmad/render/<skill>/<slug>-<hash>\npython src/scripts/render_skill.py --project-root . --skill skills/my-skill","handlingStrategy":"try-catch","validationCode":"import json\nfrom pathlib import Path\n\ndef manifest_ok(dest: Path) -> bool:\n    m = dest / \"manifest.json\"\n    try:\n        json.loads(m.read_text(encoding=\"utf-8\"))\n        return True\n    except (OSError, UnicodeError, json.JSONDecodeError):\n        return False","typeGuard":null,"tryCatchPattern":"from render_skill import render, RenderError\n\ntry:\n    entry = render(project_root, skill_dir)\nexcept RenderError as e:\n    if \"corrupt existing generation\" in str(e):\n        # remove the corrupt generation dir and re-run\n        ...\n    raise","preventionTips":["Never hand-edit generated output directories.","Commit generations to VCS so corruption is visible and recoverable.","If a render is interrupted, delete the partial generation dir before retrying."],"tags":["python","manifest","corruption","filesystem","idempotency"],"backgroundTag":null,"analyzedSha":"b70486b9bdcb0a404d329e2a763b57964e7f1360","analyzedAt":"2026-08-13T01:21:12.247Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}