{"record":{"id":"1fd0c844b8f70096","repo":"unslothai/unsloth","slug":"path-cannot-be-empty-1fd0c8","errorCode":null,"errorMessage":"Path cannot be empty","messagePattern":"Path cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"warning","filePath":"studio/backend/hub/storage/scan_folders.py","lineNumber":121,"sourceCode":"        _schema_ready = True\n\n\ndef list_scan_folders() -> list[dict]:\n    conn = get_connection()\n    try:\n        _ensure_schema(conn)\n        rows = conn.execute(\n            \"SELECT id, path, created_at FROM scan_folders ORDER BY created_at\"\n        ).fetchall()\n        return [dict(row) for row in rows]\n    finally:\n        conn.close()\n\n\ndef add_scan_folder_with_status(path: str) -> tuple[dict, bool]:\n    \"\"\"Add a readable scan folder and return its row plus whether it was inserted.\"\"\"\n    if not path or not path.strip():\n        raise ValueError(\"Path cannot be empty\")\n    normalized = os.path.realpath(os.path.expanduser(normalize_path(path.strip())))\n\n    if not os.path.exists(normalized):\n        raise ValueError(\"Path does not exist\")\n    if not os.path.isdir(normalized):\n        raise ValueError(\"Path must be a directory, not a file\")\n    if not os.access(normalized, os.R_OK | os.X_OK):\n        raise ValueError(\"Path is not readable\")\n    if is_local_filesystem_root(normalized):\n        # A local fs root (\"/\", \"C:\\\\\") would expose denied system dirs via browse;\n        # a UNC share root (\\\\server\\share) has none under it and stays registerable.\n        raise ValueError(\"The filesystem root cannot be registered\")\n    if _contains_sensitive_path_component(normalized):\n        raise ValueError(\"Credential or configuration directories are not allowed\")\n\n    is_win = platform.system() == \"Windows\"\n    check = os.path.normcase(normalized) if is_win else normalized\n    for prefix in _denied_path_prefixes():","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/hub/storage/scan_folders.py#L103-L139","documentation":"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).","triggerScenarios":"POSTing a scan-folder add request with path=\"\", path=\"   \", or a missing/null path field.","commonSituations":"Front-end form submitted before the user typed anything; a default-empty input state; JSON payload built with a None value for path.","solutions":["Trim input client-side and disable submit until non-empty.","Send a real absolute directory path, e.g. /data/models."],"exampleFix":"// before\nfetch('/api/scan-folders', {method:'POST', body: JSON.stringify({path: ''})})\n// after\nfetch('/api/scan-folders', {method:'POST', body: JSON.stringify({path: '/data/models'})})","handlingStrategy":"validation","validationCode":"def valid_scan_folder_input(path) -> bool:\n    return isinstance(path, str) and bool(path.strip())","typeGuard":"def is_nonempty_path(value: unknown) -> value is string:\n  return typeof value === 'string' && value.trim().length > 0;","tryCatchPattern":"try:\n    add_scan_folder(path)\nexcept ValueError as e:\n    if \"cannot be empty\" in str(e):\n        return  # nothing to do — caller bug or empty form; fix the form","preventionTips":["Disable submit until the path input has non-whitespace content.","Trim input before sending; reject empty strings at the API client layer."],"tags":["validation","scan-folders","user-input"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}