{"record":{"id":"2e1dfbdfe89d5a93","repo":"openai/whisper","slug":"download-target-exists-and-is-not-a-regular-file","errorCode":null,"errorMessage":"{download_target} exists and is not a regular file","messagePattern":"(.+?) exists and is not a regular file","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"whisper/__init__.py","lineNumber":61,"sourceCode":"    \"medium.en\": b\"ABzY8usPae0{>%R7<zz_OvQ{)4kMa0BMw6u5rT}kRKX;$NfYBv00*Hl@qhsU00\",\n    \"medium\": b\"ABzY8B0Jh+0{>%R7}kK1fFL7w6%<-Pf*t^=N)Qr&0RR9\",\n    \"large-v1\": b\"ABzY8r9j$a0{>%R7#4sLmoOs{s)o3~84-RPdcFk!JR<kSfC2yj\",\n    \"large-v2\": b\"ABzY8zd+h!0{>%R7=D0pU<_bnWW*tkYAhobTNnu$jnkEkXqp)j;w1Tzk)UH3X%SZd&fFZ2fC2yj\",\n    \"large-v3\": b\"ABzY8gWO1E0{>%R7(9S+Kn!D~%ngiGaR?*L!iJG9p-nab0JQ=-{D1-g00\",\n    \"large\": b\"ABzY8gWO1E0{>%R7(9S+Kn!D~%ngiGaR?*L!iJG9p-nab0JQ=-{D1-g00\",\n    \"large-v3-turbo\": b\"ABzY8j^C+e0{>%RARaKHP%t(lGR*)0g!tONPyhe`\",\n    \"turbo\": b\"ABzY8j^C+e0{>%RARaKHP%t(lGR*)0g!tONPyhe`\",\n}\n\n\ndef _download(url: str, root: str, in_memory: bool) -> Union[bytes, str]:\n    os.makedirs(root, exist_ok=True)\n\n    expected_sha256 = url.split(\"/\")[-2]\n    download_target = os.path.join(root, os.path.basename(url))\n\n    if os.path.exists(download_target) and not os.path.isfile(download_target):\n        raise RuntimeError(f\"{download_target} exists and is not a regular file\")\n\n    if os.path.isfile(download_target):\n        with open(download_target, \"rb\") as f:\n            model_bytes = f.read()\n        if hashlib.sha256(model_bytes).hexdigest() == expected_sha256:\n            return model_bytes if in_memory else download_target\n        else:\n            warnings.warn(\n                f\"{download_target} exists, but the SHA256 checksum does not match; re-downloading the file\"\n            )\n\n    with urllib.request.urlopen(url) as source, open(download_target, \"wb\") as output:\n        with tqdm(\n            total=int(source.info().get(\"Content-Length\")),\n            ncols=80,\n            unit=\"iB\",\n            unit_scale=True,\n            unit_divisor=1024,","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/openai/whisper/blob/5f86d1d86363843179951550570367b37c5d6f78/whisper/__init__.py#L43-L79","documentation":"Raised by whisper._download() before fetching a model checkpoint. The path where the library wants to store the model (download_root/<model>.pt) already exists but is not a regular file — typically a directory, a named pipe, or a dangling special file. The library refuses to overwrite non-file entries to avoid destroying data or writing into a directory.","triggerScenarios":"Calling whisper.load_model('base') (or _download directly) when ~/.cache/whisper/base.pt (or $XDG_CACHE_HOME/whisper/base.pt, or a custom download_root) exists as a directory; e.g. someone previously ran 'mkdir -p ~/.cache/whisper/base.pt' or a bad symlink points to a directory.","commonSituations":"CI containers or shared servers where cache dirs were pre-created with wrong structure; users who unzipped a model into a folder named like the .pt file; symlinks from a shared model store pointing at a directory; a failed earlier tool that created a directory instead of a file.","solutions":["Inspect the path: ls -la ~/.cache/whisper/ and check what <model>.pt actually is","If it is a directory containing the checkpoint, move the .pt file out of it or point load_model's download_root at the correct directory","Remove or rename the offending directory: rm -rf ~/.cache/whisper/<model>.pt (after confirming it holds nothing valuable), then retry load_model","Pass an explicit download_root to whisper.load_model pointing at an empty, writable directory"],"exampleFix":"# before\n# ~/.cache/whisper/base.pt is a directory -> RuntimeError\nmodel = whisper.load_model(\"base\")\n\n# after\nimport os, shutil\np = os.path.expanduser(\"~/.cache/whisper/base.pt\")\nif os.path.exists(p) and not os.path.isfile(p):\n    shutil.rmtree(p)  # or move real checkpoint out first\nmodel = whisper.load_model(\"base\")","handlingStrategy":"validation","validationCode":"import os\n\ndef safe_download_root_ok(root: str, model: str) -> bool:\n    target = os.path.join(root, f\"{model}.pt\")\n    return not os.path.exists(target) or os.path.isfile(target)","typeGuard":null,"tryCatchPattern":"try:\n    model = whisper.load_model(name, download_root=root)\nexcept RuntimeError as e:\n    if \"exists and is not a regular file\" in str(e):\n        # inspect/remove the offending path, then retry once with a clean root\n        raise","preventionTips":["Pre-create the download_root yourself and assert it contains only *.pt regular files before load_model","Never name directories after model files; keep checkpoints flat inside the cache dir","In containers, mount the whisper cache as a volume and verify its layout in the entrypoint"],"tags":["filesystem","model-download","cache","configuration"],"backgroundTag":null,"analyzedSha":"5f86d1d86363843179951550570367b37c5d6f78","analyzedAt":"2026-08-14T18:53:59.547Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}