{"record":{"id":"f811e69bdabcf59c","repo":"unslothai/unsloth","slug":"path-cannot-be-empty","errorCode":null,"errorMessage":"Path cannot be empty","messagePattern":"Path cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"studio/backend/core/rag/folder_sync.py","lineNumber":129,"sourceCode":"\n    error = redact_native_paths(str(exc) or exc.__class__.__name__)\n    if native_path:\n        error = error.replace(native_path, \"<native_path>\")\n        error = error.replace(os.path.normpath(native_path), \"<native_path>\")\n    return error\n\n\ndef _is_within(root: str, path: str) -> bool:\n    try:\n        return os.path.normcase(os.path.commonpath([root, path])) == os.path.normcase(root)\n    except ValueError:\n        return False\n\n\ndef validate_folder_path(path: str) -> str:\n    \"\"\"Apply the existing model scan-folder policy without persisting there.\"\"\"\n    if not path or not path.strip() or \"\\x00\" in path:\n        raise ValueError(\"Path cannot be empty\")\n    expanded = os.path.abspath(os.path.expanduser(path))\n    try:\n        if stat.S_ISLNK(os.lstat(expanded).st_mode):\n            raise ValueError(\"Symbolic-link folders are not allowed\")\n    except OSError as exc:\n        raise ValueError(\"Path does not exist\") from exc\n    normalized = os.path.realpath(expanded)\n    uploads_root = os.path.realpath(str(rag_uploads_root()))\n    if _paths_overlap(_path_key(normalized), _path_key(uploads_root)):\n        raise ValueError(\"The managed RAG uploads folder cannot be linked\")\n\n    from hub.storage.scan_folders import (\n        contains_sensitive_path_component,\n        is_denied_system_path,\n    )\n    from utils.paths.external_media import is_local_filesystem_root\n\n    if not os.path.isdir(normalized):","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/rag/folder_sync.py#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nvalidate_folder_path(request.folder_path or \"\")\n\n# after\npath = (request.folder_path or \"\").strip()\nif not path:\n    raise ValueError(\"Path cannot be empty\")\nvalidate_folder_path(path)","handlingStrategy":"validation","validationCode":"def folder_path_submittable(raw: str | None) -> bool:\n    return bool(raw) and bool(raw.strip()) and \"\\x00\" not in raw","typeGuard":"def is_submittable_folder_path(raw: str | None) -> TypeGuard[str]:\n    return isinstance(raw, str) and bool(raw.strip()) and \"\\x00\" not in raw","tryCatchPattern":"try:\n    normalized = validate_folder_path(user_input)\nexcept ValueError as e:\n    if str(e) != \"Path cannot be empty\":\n        raise\n    return bad_request(\"folder path is required\")","preventionTips":["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."],"tags":["validation","paths","user-input","rag"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}