unslothai/unsloth · warning · ValueError
Path cannot be empty
Error message
Path cannot be empty
What it means
ValueError raised by validate_folder_path when the candidate linked-folder path is falsy, whitespace-only, or contains a NUL byte (\x00). This is the first and cheapest guard in the folder-registration policy that mirrors the model scan-folder rules; empty/NUL paths are rejected outright before any filesystem access, since os.path.abspath/lstat behavior on such inputs is undefined or OS-dependent.
Source
Thrown at studio/backend/core/rag/folder_sync.py:129
error = redact_native_paths(str(exc) or exc.__class__.__name__)
if native_path:
error = error.replace(native_path, "<native_path>")
error = error.replace(os.path.normpath(native_path), "<native_path>")
return error
def _is_within(root: str, path: str) -> bool:
try:
return os.path.normcase(os.path.commonpath([root, path])) == os.path.normcase(root)
except ValueError:
return False
def validate_folder_path(path: str) -> str:
"""Apply the existing model scan-folder policy without persisting there."""
if not path or not path.strip() or "\x00" in path:
raise ValueError("Path cannot be empty")
expanded = os.path.abspath(os.path.expanduser(path))
try:
if stat.S_ISLNK(os.lstat(expanded).st_mode):
raise ValueError("Symbolic-link folders are not allowed")
except OSError as exc:
raise ValueError("Path does not exist") from exc
normalized = os.path.realpath(expanded)
uploads_root = os.path.realpath(str(rag_uploads_root()))
if _paths_overlap(_path_key(normalized), _path_key(uploads_root)):
raise ValueError("The managed RAG uploads folder cannot be linked")
from hub.storage.scan_folders import (
contains_sensitive_path_component,
is_denied_system_path,
)
from utils.paths.external_media import is_local_filesystem_root
if not os.path.isdir(normalized):View on GitHub (pinned to 203007d190)
Solutions
- Pass a non-empty, trimmed absolute or ~ -relative directory path.
- Sanitize input on the client: strip whitespace and reject empty submissions before calling the API.
- If the path came from a file, re-read it with the correct encoding to drop embedded NUL bytes.
Example fix
# before
validate_folder_path(request.folder_path or "")
# after
path = (request.folder_path or "").strip()
if not path:
raise ValueError("Path cannot be empty")
validate_folder_path(path) Defensive patterns
Strategy: validation
Validate before calling
def folder_path_submittable(raw: str | None) -> bool:
return bool(raw) and bool(raw.strip()) and "\x00" not in raw Type guard
def is_submittable_folder_path(raw: str | None) -> TypeGuard[str]:
return isinstance(raw, str) and bool(raw.strip()) and "\x00" not in raw Try / catch
try:
normalized = validate_folder_path(user_input)
except ValueError as e:
if str(e) != "Path cannot be empty":
raise
return bad_request("folder path is required") Prevention
- Make the folder field required client-side and disable submit while empty.
- Trim input and reject NUL bytes before it reaches the API.
- Decode path inputs as UTF-8 strictly so binary garbage (embedded NULs) is caught at the boundary.
When it happens
Trigger: Calling validate_folder_path(''), validate_folder_path(' '), or a path string containing '\x00' (often the result of decoding a binary/UTF-16 artifact); a frontend form submitting an empty folder field to the folder-link API.
Common situations: UI text field submitted without entering a path; paths read from mis-encoded files (UTF-16 with leftover NULs); scripted/API clients passing null coerced to empty string.
Related errors
- The managed RAG uploads folder cannot be linked
- Path must be a directory, not a file
- Symbolic-link folders are not allowed
- Path does not exist
- Path is not readable
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/f811e69bdabcf59c.
Report an issue: GitHub.