sinelaw/fresh · error · ValueError
empty path
Error message
empty path
What it means
validate_path in the remote agent service canonicalizes any path before file operations (read, write, sudo_write, stat, ls, rm). It raises ValueError('empty path') when the argument is falsy (None or ""), because a canonicalized empty path is meaningless and would otherwise resolve to the process CWD and allow unintended operations.
Solutions
- Provide a non-empty absolute (or workspace-relative) path in the request.
- On the client side, validate the path is a non-empty string before sending the command.
- If the path is meant to be optional, handle that in the command layer before calling validate_path instead of passing ""/None.
- Catch ValueError from the command and return a clear client error indicating the missing path parameter.
Example fix
// before
result = agent.cmd_read("")
// after
path = request.get("path") or ""
if not path:
raise BadRequest("'path' is required and must be non-empty")
result = agent.cmd_read(path) Defensive patterns
Strategy: validation
Validate before calling
if not isinstance(p, str) or not p:
raise ValueError("path must be a non-empty string") Type guard
def is_valid_path(p) -> bool:
return isinstance(p, str) and bool(p) Try / catch
try:
canonical = validate_path(p)
except ValueError as e:
if str(e) == "empty path":
return error_response(400, "'path' is required and must be non-empty")
raise Prevention
- Validate that the path field is present and non-empty at the API boundary before dispatching commands.
- Distinguish 'optional path' from 'empty path' explicitly in request schemas.
- Use request validation (schema/pydantic) so missing path fields are rejected before reaching validate_path.
- Test the read/write/ls/rm commands with empty and null path payloads.
When it happens
Trigger: Any of the remote agent commands cmd_read, cmd_write, cmd_sudo_write, cmd_stat, cmd_ls, cmd_rm invoked with p=None or p="" — e.g. a client request whose 'path' field is missing, null, or an empty string reaches agent.py:50.
Common situations: API clients omitting the path field in the JSON request body; frontends sending empty inputs from unfilled form fields; protocol/serialization bugs dropping empty strings; defaults where None is used for 'not provided'.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- project path does not exist
- ${built.error}
- folder name must not be empty
- sudo tee failed
- empty script: pass a file, or pipe the source on stdin
AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13).
Data as JSON: /api/errors/adc55a69b97efa95.
Report an issue: GitHub.
Appendix: source
Thrown at crates/fresh-editor/src/services/remote/agent.py:50
with write_lock:
sys.stdout.write(line)
sys.stdout.flush()
def b64(data):
"""Encode bytes to base64 string."""
return base64.b64encode(data).decode("ascii")
def unb64(s):
"""Decode base64 string to bytes."""
return base64.b64decode(s)
def validate_path(p):
"""Validate and canonicalize a path."""
if not p:
raise ValueError("empty path")
expanded = os.path.expanduser(p)
if not os.path.isabs(expanded):
expanded = os.path.abspath(expanded)
return os.path.realpath(expanded)
# === File Operations ===
def cmd_read(id, p):
"""Read file contents, streaming in chunks for large files."""
path = validate_path(p["path"])
off = p.get("off", 0)
length = p.get("len")
with open(path, "rb") as f:
if off:
f.seek(off)View on GitHub (pinned to 67894ca546)