unslothai/unsloth · error · ValueError

The selected cache location is not a folder.

Error message

The selected cache location is not a folder.

What it means

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.

Source

Thrown at studio/backend/utils/hf_cache_settings.py:276

            contains_sensitive_path_component,
            is_denied_system_path,
        )
    except ImportError:
        contains_sensitive_path_component = is_denied_system_path = None
    if is_denied_system_path is not None and is_denied_system_path(str(resolved)):
        raise ValueError("System folders cannot be used for model downloads.")
    if contains_sensitive_path_component is not None and contains_sensitive_path_component(
        str(resolved)
    ):
        raise ValueError("Credential or config folders cannot be used for model downloads.")

    parent = resolved.parent
    if not parent.exists() or not parent.is_dir():
        raise ValueError("The parent folder does not exist.")
    try:
        resolved.mkdir(exist_ok = True)
        if not resolved.is_dir():
            raise ValueError("The selected cache location is not a folder.")
        for child in (resolved / "hub", resolved / "xet"):
            child.mkdir(exist_ok = True)
            with tempfile.NamedTemporaryFile(prefix = ".unsloth-write-test-", dir = child):
                pass
    except PermissionError as exc:
        raise ValueError("Studio does not have permission to write to this folder.") from exc
    except OSError as exc:
        raise ValueError(f"Studio cannot use this cache folder: {exc}") from exc
    return resolved


def _stored_history() -> list[Path]:
    try:
        from storage.studio_db import get_app_setting
        raw = get_app_setting(CACHE_HISTORY_SETTING_KEY, [])
    except Exception:
        raw = []
    if not isinstance(raw, list):

View on GitHub (pinned to 203007d190)

Solutions

  1. Remove the offending non-directory: rm /data/hf-cache (verify it is not needed), then save the setting again
  2. If it is a broken symlink, delete it or repoint it at a real directory
  3. Re-run the settings save; the code will now mkdir a genuine directory

Example fix

# before
touch /data/hf-cache                    # a file occupies the name
set_hf_cache_home('/data/hf-cache')    # ValueError: not a folder

# after
rm /data/hf-cache
set_hf_cache_home('/data/hf-cache')    # ok, directory created
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def target_is_dir_or_absent(raw: str) -> bool:
    p = Path(raw).expanduser().resolve(strict=False)
    return not p.exists() or p.is_dir()

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/86894bff38b7a166. Report an issue: GitHub.