{"record":{"id":"1fe6ada0a0715dfb","repo":"lllyasviel/Fooocus","slug":"str-e-file-corrupted-path-fooocus-has-tried","errorCode":null,"errorMessage":"{str(e)}\nFile corrupted: {path} \nFooocus has tried to move the corrupted file to {path}.corrupted \nYou may try again now and Fooocus will download models again. \n","messagePattern":"(.+?)\nFile corrupted: (.+?) \nFooocus has tried to move the corrupted file to (.+?)\\.corrupted \nYou may try again now and Fooocus will download models again\\. \n","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/patch.py","lineNumber":481,"sourceCode":"        result = None\n        try:\n            result = original_loader(*args, **kwargs)\n        except Exception as e:\n            result = None\n            exp = str(e) + '\\n'\n            for path in list(args) + list(kwargs.values()):\n                if isinstance(path, str):\n                    if os.path.exists(path):\n                        exp += f'File corrupted: {path} \\n'\n                        corrupted_backup_file = path + '.corrupted'\n                        if os.path.exists(corrupted_backup_file):\n                            os.remove(corrupted_backup_file)\n                        os.replace(path, corrupted_backup_file)\n                        if os.path.exists(path):\n                            os.remove(path)\n                        exp += f'Fooocus has tried to move the corrupted file to {corrupted_backup_file} \\n'\n                        exp += f'You may try again now and Fooocus will download models again. \\n'\n            raise ValueError(exp)\n        return result\n\n    setattr(module, loader_name, loader)\n    return\n\n\ndef patch_all():\n    if ldm_patched.modules.model_management.directml_enabled:\n        ldm_patched.modules.model_management.lowvram_available = True\n        ldm_patched.modules.model_management.OOM_EXCEPTION = Exception\n\n    patch_all_precision()\n    patch_all_clip()\n\n    if not hasattr(ldm_patched.modules.model_management, 'load_models_gpu_origin'):\n        ldm_patched.modules.model_management.load_models_gpu_origin = ldm_patched.modules.model_management.load_models_gpu\n\n    ldm_patched.modules.model_management.load_models_gpu = patched_load_models_gpu","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/modules/patch.py#L463-L499","documentation":"This ValueError is raised by Fooocus's build_loaded() wrapper (modules/patch.py:454-485), which monkey-patches checkpoint/VAE/LoRA loader functions in ldm_patched. When the underlying loader (e.g. torch.load / safetensors loading) throws any exception, the wrapper assumes the model file on disk is corrupted: it iterates the loader's string args/kwargs, renames every existing file to '<path>.corrupted' (removing a previous .corrupted backup first), and re-raises a ValueError whose text is the original exception plus 'File corrupted: <path>' and instructions to retry so Fooocus re-downloads the model. Important: the corruption diagnosis is a heuristic — ANY loader failure (not just a bad file) triggers the rename, so genuine non-corruption errors (CUDA OOM, unsupported file version, missing dependency) can also quarantine a healthy model file.","triggerScenarios":"Calling any patched loader with a file path where loading fails: loading a truncated safetensors/checkpoint (interrupted download, disk filled mid-download), a file that is actually an HTML error page saved with a .safetensors/.ckpt name (mirror redirect), a model whose pickle/safetensors format the installed torch cannot deserialize, or any other exception thrown inside ldm_patched.modules.checkpoint.load_checkpoint / VAE / LoRA load paths. Concretely: the user selects a base model or VAE in the Fooocus UI and generation starts -> build_loaded's loader() catches the original_loader exception -> renames e.g. models/checkpoints/foo.safetensors to foo.safetensors.corrupted -> raises this ValueError.","commonSituations":"Interrupted or proxied downloads in regions where HuggingFace is blocked (file is a redirect page or partial), disk-full during initial model download, an older .ckpt pickled with a torch version incompatible with the runtime, a healthy file being quarantined because the real failure was an OOM or a code bug inside the loader, and moving/copying model files between machines with a filesystem that truncated them.","solutions":["Check the first line of the error message (the original exception, str(e)) — it names the true cause. If it is a download/unpickling/deserialization error, the file really is bad; if it is CUDA OOM or an AttributeError, the file is fine and you should restore it from the .corrupted backup.","If the file was legit: restore it with `mv <path>.corrupted <path>` (or just let Fooocus re-download it by clicking Generate again), then fix the actual root cause (free VRAM, fix disk space, update torch) before retrying.","If the file really is corrupt (common with blocked/redirected HuggingFace downloads): delete the .corrupted file, re-download the model manually (e.g. `huggingface-cli download` or a browser) into models/checkpoints (or models/vae, models/loras), verifying the file size matches the hub's reported size.","Verify integrity before retry loops: compare file sizes/SHA256 against the HuggingFace repo metadata; a mismatch of a few KB vs several GB means a truncated transfer.","If a healthy model keeps getting quarantined by an unrelated loader bug on every launch, temporarily rename the file back and patch/report the underlying exception instead of letting the wrapper loop-delete your models."],"exampleFix":"# before: model keeps failing to load and Fooocus quarantines it\n# (models/checkpoints/my_model.safetensors -> my_model.safetensors.corrupted)\n\n# after: verify integrity and restore or re-download\nimport os, hashlib\npath = 'models/checkpoints/my_model.safetensors'\nif os.path.exists(path + '.corrupted'):\n    size = os.path.getsize(path + '.corrupted')\n    print('quarantined size:', size)  # compare with HF repo size\n    if size > 1_000_000:            # plausible full file -> restore\n        os.replace(path + '.corrupted', path)\n    else:                            # truncated/redirect page -> fetch again\n        from huggingface_hub import hf_hub_download\n        hf_hub_download('stabilityai/stable-diffusion-xl-base-1.0',\n                        'sd_xl_base_1.0.safetensors', local_dir='models/checkpoints')","handlingStrategy":"try-catch","validationCode":"# Pre-flight check before pointing the pipeline at a model file\nimport os\n\ndef model_file_looks_valid(path, min_bytes=100_000_000):\n    if not os.path.exists(path):\n        return False, 'missing'\n    if path.endswith('.corrupted') or os.path.exists(path + '.corrupted'):\n        return False, 'previously quarantined by Fooocus'\n    size = os.path.getsize(path)\n    if size < min_bytes:  # redirect pages / partial downloads are tiny\n        return False, f'suspicious size {size}'\n    with open(path, 'rb') as f:\n        magic = f.read(8)\n    if path.endswith('.safetensors') and magic[:3] not in (b'[{\"', b'[ {'):\n        return False, 'not a safetensors container (likely HTML error page)'\n    return True, 'ok'","typeGuard":null,"tryCatchPattern":"from modules.patch import patch_all  # loading happens after patch_all()\n\ntry:\n    # any generation / model load that can hit the quarantining loader\n    task = worker(*args)\nexcept ValueError as e:\n    msg = str(e)\n    if 'File corrupted:' in msg:\n        original = msg.splitlines()[0]              # the REAL underlying exception\n        if 'out of memory' in original.lower():\n            restore_quarantined_files(msg)          # file is fine; fix VRAM instead\n            raise RuntimeError('OOM misreported as corruption: ' + original)\n        else:\n            # genuinely bad file: let Fooocus re-download, or fetch manually\n            log_quarantined_paths(msg)\n    else:\n        raise","preventionTips":["Download models with huggingface-cli or a resumable client and verify size/SHA256 against the hub before adding them to models/checkpoints.","Watch the first line of the wrapped message — it is the original loader exception; treat 'File corrupted' lines as the wrapper's guess, not ground truth.","Keep a backup of rare/community checkpoints: the wrapper renames them to .corrupted and a re-download may be impossible if the source is gone.","Ensure enough free disk space before first launch so initial model downloads cannot be truncated.","If you run a custom loader patch inside ldm_patched, remember ANY exception it raises will quarantine the model file it was given."],"tags":["fooocus","model-loading","corrupted-file","download","monkey-patch","file-io"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}