unslothai/unsloth · warning · ValueError

Path cannot be empty

Error message

Path cannot be empty

What it means

Validation error from add_scan_folder_with_status: the path argument is None, empty, or whitespace-only after stripping. It is the first guard in the scan-folder registration pipeline; the endpoint converts it to a user-facing error (typically HTTP 400).

Source

Thrown at studio/backend/hub/storage/scan_folders.py:121

        _schema_ready = True


def list_scan_folders() -> list[dict]:
    conn = get_connection()
    try:
        _ensure_schema(conn)
        rows = conn.execute(
            "SELECT id, path, created_at FROM scan_folders ORDER BY created_at"
        ).fetchall()
        return [dict(row) for row in rows]
    finally:
        conn.close()


def add_scan_folder_with_status(path: str) -> tuple[dict, bool]:
    """Add a readable scan folder and return its row plus whether it was inserted."""
    if not path or not path.strip():
        raise ValueError("Path cannot be empty")
    normalized = os.path.realpath(os.path.expanduser(normalize_path(path.strip())))

    if not os.path.exists(normalized):
        raise ValueError("Path does not exist")
    if not os.path.isdir(normalized):
        raise ValueError("Path must be a directory, not a file")
    if not os.access(normalized, os.R_OK | os.X_OK):
        raise ValueError("Path is not readable")
    if is_local_filesystem_root(normalized):
        # A local fs root ("/", "C:\\") would expose denied system dirs via browse;
        # a UNC share root (\\server\share) has none under it and stays registerable.
        raise ValueError("The filesystem root cannot be registered")
    if _contains_sensitive_path_component(normalized):
        raise ValueError("Credential or configuration directories are not allowed")

    is_win = platform.system() == "Windows"
    check = os.path.normcase(normalized) if is_win else normalized
    for prefix in _denied_path_prefixes():

View on GitHub (pinned to 203007d190)

Solutions

  1. Trim input client-side and disable submit until non-empty.
  2. Send a real absolute directory path, e.g. /data/models.

Example fix

// before
fetch('/api/scan-folders', {method:'POST', body: JSON.stringify({path: ''})})
// after
fetch('/api/scan-folders', {method:'POST', body: JSON.stringify({path: '/data/models'})})
Defensive patterns

Strategy: validation

Validate before calling

def valid_scan_folder_input(path) -> bool:
    return isinstance(path, str) and bool(path.strip())

Type guard

def is_nonempty_path(value: unknown) -> value is string:
  return typeof value === 'string' && value.trim().length > 0;

Try / catch

try:
    add_scan_folder(path)
except ValueError as e:
    if "cannot be empty" in str(e):
        return  # nothing to do — caller bug or empty form; fix the form

Prevention

When it happens

Trigger: POSTing a scan-folder add request with path="", path=" ", or a missing/null path field.

Common situations: Front-end form submitted before the user typed anything; a default-empty input state; JSON payload built with a None value for path.

Related errors


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