{"record":{"id":"0a82b266ad8e32e9","repo":"nexu-io/open-design","slug":"run-dir-already-exists-and-is-not-empty-pass","errorCode":null,"errorMessage":"{run_dir} already exists and is not empty; pass --force to reuse it","messagePattern":"(.+?) already exists and is not empty; pass --force to reuse it","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"skills/hatch-pet/scripts/prepare_pet_run.py","lineNumber":582,"sourceCode":"    raw_reference_paths = [\n        Path(raw_path).expanduser().resolve() for raw_path in args.reference\n    ]\n\n    args.display_name = infer_name(args, raw_reference_paths)\n    args.pet_name = (args.pet_name or args.display_name).strip()\n    args.description = infer_description(args, raw_reference_paths)\n    args.pet_notes = infer_pet_notes(args, raw_reference_paths)\n    args.pet_id = slugify(args.pet_id or args.pet_name or args.display_name)\n    if not args.pet_id:\n        raise SystemExit(\"pet id must contain at least one letter or digit\")\n\n    run_dir = (\n        Path(args.output_dir).expanduser().resolve()\n        if args.output_dir\n        else default_output_dir(args.pet_id).resolve()\n    )\n    if run_dir.exists() and any(run_dir.iterdir()) and not args.force:\n        raise SystemExit(\n            f\"{run_dir} already exists and is not empty; pass --force to reuse it\"\n        )\n    run_dir.mkdir(parents=True, exist_ok=True)\n\n    ref_dir = run_dir / \"references\"\n    prompt_dir = run_dir / \"prompts\"\n    row_prompt_dir = prompt_dir / \"rows\"\n    for directory in [\n        ref_dir,\n        prompt_dir,\n        row_prompt_dir,\n        run_dir / \"decoded\",\n        run_dir / \"qa\",\n    ]:\n        directory.mkdir(parents=True, exist_ok=True)\n\n    copied_refs: list[dict[str, object]] = []\n    copied_ref_paths: list[Path] = []","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/skills/hatch-pet/scripts/prepare_pet_run.py#L564-L600","documentation":"Raised by prepare_pet_run.py when the resolved run directory already exists and contains at least one entry, and --force was not passed. It is a deliberate guard so an in-progress or previously-generated pet run is never silently overwritten. The script resolves run_dir from --output-dir (or default_output_dir(pet_id)) and treats any non-empty target as occupied.","triggerScenarios":"Running prepare_pet_run.py a second time with the same --pet-id (same default_output_dir), or pointing --output-dir at a folder that already holds files; re-running after a partial/failed generation without cleaning up.","commonSituations":"Iterating on a pet design and forgetting the previous run is still on disk; CI/local rerun after a crash left the run_dir partially populated; two teammates sharing a workspace whose default output root collides.","solutions":["Pass --force if you intentionally want to reuse the existing run_dir.","Move or delete the existing run_dir before re-running, e.g. rm -rf <run_dir>.","Use a distinct --pet-id (which changes default_output_dir) or a fresh --output-dir for the new attempt.","If the directory is unexpectedly non-empty (leftover dotfiles), inspect run_dir.iterdir() and clean the stray entries."],"exampleFix":"# before\npython skills/hatch-pet/scripts/prepare_pet_run.py --pet-name \"Fenrir\"\n# after (reuse intentionally)\npython skills/hatch-pet/scripts/prepare_pet_run.py --pet-name \"Fenrir\" --force","handlingStrategy":"validation","validationCode":"from pathlib import Path\nrun_dir = Path(args.output_dir or default_output_dir(args.pet_id)).expanduser().resolve()\nif run_dir.exists() and any(run_dir.iterdir()) and not args.force:\n    print(f\"refusing to overwrite {run_dir}; pass --force or pick a new --output-dir\")\n    raise SystemExit(2)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit --output-dir for CI runs so default_output_dir collisions cannot happen.","Treat run_dir as disposable: clean it before re-preparing instead of relying on --force.","If --force is needed often, wrap the script in a make target that wipes the run_dir first."],"tags":["filesystem","cli","hatch-pet","idempotency"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}