{"record":{"id":"eeb4238c5681ed48","repo":"Fosowl/agenticSeek","slug":"empty-path","errorCode":null,"errorMessage":"Empty path","messagePattern":"Empty path","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sources/workspace.py","lineNumber":80,"sourceCode":"    \"\"\"Return True when path resolves inside directory (no traversal escape).\"\"\"\n    try:\n        path_real = os.path.realpath(os.path.abspath(path))\n        dir_real = os.path.realpath(os.path.abspath(directory))\n        return os.path.commonpath([path_real, dir_real]) == dir_real\n    except ValueError:\n        return False\n\n\ndef resolve_workspace_path(path: str, work_dir: str | None = None) -> str:\n    \"\"\"\n    Resolve a user or model-provided path inside the agent workspace.\n\n    Raises:\n        ValueError: empty path\n        PermissionError: resolved path escapes the workspace\n    \"\"\"\n    if path is None or not str(path).strip():\n        raise ValueError(\"Empty path\")\n\n    base = work_dir or get_work_dir()\n    candidate = str(path).strip()\n    if os.path.isabs(candidate):\n        resolved = os.path.realpath(candidate)\n    else:\n        resolved = os.path.realpath(os.path.join(base, candidate))\n\n    if not is_within_directory(resolved, base):\n        raise PermissionError(\n            f\"Path '{path}' is outside the agent workspace ({base})\"\n        )\n    return resolved\n","sourceCodeStart":62,"sourceCodeEnd":94,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/workspace.py#L62-L94","documentation":"resolve_workspace_path() rejects any path argument that is None or consists only of whitespace by raising ValueError('Empty path'). The library requires a concrete, non-empty path string because it must join/resolve it against a workspace base directory; an empty path has no meaning there.","triggerScenarios":"Calling resolve_workspace_path(None, ...) or resolve_workspace_path('   ', ...); passing an unset config variable (e.g. resolve_workspace_path(cfg.get('path'))); passing an empty string from a CLI arg or environment variable default.","commonSituations":"Config files where the workspace path key is missing or set to '' ; environment variables like WORK_DIR not set; callers defaulting with something like os.environ.get('PATH_VAR', '') which yields an empty string instead of None; upstream normalization (e.g. .strip()) that emptied an otherwise valid value.","solutions":["Ensure the path argument is a non-empty string before calling resolve_workspace_path; fall back to a sensible default (e.g. '.') if the variable is unset.","Read the config/env value with a None-preserving default: os.environ.get('WORK_DIR') or DEFAULT_DIR instead of os.environ.get('WORK_DIR', '').","Wrap the call in try/except ValueError and surface a clear message about which config key supplied the empty path."],"exampleFix":"// before\nresolved = resolve_workspace_path(cfg.get('input_path'))\n// after\nraw = cfg.get('input_path')\nif raw is None or not str(raw).strip():\n    raise ValueError(\"config key 'input_path' must be a non-empty path\")\nresolved = resolve_workspace_path(raw)","handlingStrategy":"validation","validationCode":"def is_valid_path_arg(p):\n    return p is not None and str(p).strip() != \"\"\n\nif not is_valid_path_arg(raw_path):\n    raise ValueError(\"path argument must be a non-empty string\")","typeGuard":"def has_path(p) -> bool:\n    return p is not None and isinstance(p, (str, bytes, os.PathLike)) and str(p).strip() != \"\"","tryCatchPattern":"try:\n    resolved = resolve_workspace_path(raw)\nexcept ValueError:\n    logger.error(\"empty or missing path supplied to resolve_workspace_path\")\n    resolved = resolve_workspace_path(DEFAULT_RELATIVE_PATH)","preventionTips":["Use 'or DEFAULT' (not '' defaults) when reading path values from env/config.","Validate all path-bearing config keys at startup, before any resolution calls.","Never pass values straight from cfg.get() / os.environ.get() into path APIs without an emptiness check.","Unit-test the empty/whitespace-only path cases (the library's own tests do exactly this)."],"tags":["python","valueerror","path","validation","empty-argument"],"backgroundTag":"empty-path-argument","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}