{"record":{"id":"86894bff38b7a166","repo":"unslothai/unsloth","slug":"the-selected-cache-location-is-not-a-folder","errorCode":null,"errorMessage":"The selected cache location is not a folder.","messagePattern":"The selected cache location is not a folder\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/utils/hf_cache_settings.py","lineNumber":276,"sourceCode":"            contains_sensitive_path_component,\n            is_denied_system_path,\n        )\n    except ImportError:\n        contains_sensitive_path_component = is_denied_system_path = None\n    if is_denied_system_path is not None and is_denied_system_path(str(resolved)):\n        raise ValueError(\"System folders cannot be used for model downloads.\")\n    if contains_sensitive_path_component is not None and contains_sensitive_path_component(\n        str(resolved)\n    ):\n        raise ValueError(\"Credential or config folders cannot be used for model downloads.\")\n\n    parent = resolved.parent\n    if not parent.exists() or not parent.is_dir():\n        raise ValueError(\"The parent folder does not exist.\")\n    try:\n        resolved.mkdir(exist_ok = True)\n        if not resolved.is_dir():\n            raise ValueError(\"The selected cache location is not a folder.\")\n        for child in (resolved / \"hub\", resolved / \"xet\"):\n            child.mkdir(exist_ok = True)\n            with tempfile.NamedTemporaryFile(prefix = \".unsloth-write-test-\", dir = child):\n                pass\n    except PermissionError as exc:\n        raise ValueError(\"Studio does not have permission to write to this folder.\") from exc\n    except OSError as exc:\n        raise ValueError(f\"Studio cannot use this cache folder: {exc}\") from exc\n    return resolved\n\n\ndef _stored_history() -> list[Path]:\n    try:\n        from storage.studio_db import get_app_setting\n        raw = get_app_setting(CACHE_HISTORY_SETTING_KEY, [])\n    except Exception:\n        raw = []\n    if not isinstance(raw, list):","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/hf_cache_settings.py#L258-L294","documentation":"Raised inside the writability probe after resolved.mkdir(exist_ok=True) succeeds (or the path already exists) but resolved.is_dir() is False — meaning the path exists yet is not a directory, typically a regular file, a broken symlink, or a special file. This is a belt-and-braces check because mkdir(exist_ok=True) silently succeeds when the path already exists regardless of type.","triggerScenarios":"set_hf_cache_home('/data/hf-cache') when /data/hf-cache is an existing regular file; a dangling symlink at the target; a device node or socket occupying the name. The parent checks and mkdir have already passed when this fires.","commonSituations":"A previous tool or shell redirect created a file where the user expects a folder; stale symlinks to a deleted directory; placeholder files created to 'reserve' a location.","solutions":["Remove the offending non-directory: rm /data/hf-cache (verify it is not needed), then save the setting again","If it is a broken symlink, delete it or repoint it at a real directory","Re-run the settings save; the code will now mkdir a genuine directory"],"exampleFix":"# before\ntouch /data/hf-cache                    # a file occupies the name\nset_hf_cache_home('/data/hf-cache')    # ValueError: not a folder\n\n# after\nrm /data/hf-cache\nset_hf_cache_home('/data/hf-cache')    # ok, directory created","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef target_is_dir_or_absent(raw: str) -> bool:\n    p = Path(raw).expanduser().resolve(strict=False)\n    return not p.exists() or p.is_dir()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not pre-create placeholder files at the intended cache path","Clean stale/dangling symlinks before selecting the location"],"tags":["huggingface","cache","filesystem","validation","symlink"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}