usestrix/strix · error · ValueError

Path exists but is not a directory: {target}

Error message

Path exists but is not a directory: {target}

What it means

Raised by infer_target_type when the target path exists on disk but is neither a directory nor a recognizable API spec file. Strix happily accepts existing directories as local code and files detected by detect_spec_format (OpenAPI/Swagger/Postman); any other existing file — a README, a random .txt, a lockfile — falls through to this error.

Source

Thrown at strix/interface/utils.py:1175

        ip_obj = ipaddress.ip_address(target)
    except ValueError:
        pass
    else:
        return "ip_address", {"target_ip": str(ip_obj)}

    path = Path(target).expanduser()
    try:
        if path.exists():
            if path.is_dir():
                check_mountable_dir(path)
                return "local_code", {"target_path": str(path.resolve())}
            spec_format = detect_spec_format(path)
            if spec_format is not None:
                return "api_spec", {
                    "target_spec": str(path.resolve()),
                    "spec_format": spec_format,
                }
            raise ValueError(f"Path exists but is not a directory: {target}")
    except (OSError, RuntimeError) as e:
        raise ValueError(f"Invalid path: {target} - {e!s}") from e

    if target.endswith(".git"):
        return "repository", {"target_repo": target}

    if "/" in target:
        host_part, _, path_part = target.partition("/")
        if "." in host_part and not host_part.startswith(".") and path_part:
            full_url = f"https://{target}"
            if _is_http_git_repo(full_url):
                return "repository", {"target_repo": full_url}
            return "web_application", {"target_url": full_url}

    if "." in target and "/" not in target and not target.startswith("."):
        parts = target.split(".")
        if len(parts) >= 2 and all(p and p.strip() for p in parts):
            return "web_application", {"target_url": f"https://{target}"}

View on GitHub (pinned to 8551339130)

Solutions

  1. Point -t at the project directory containing the code instead of an individual file.
  2. If the file is meant to be an API spec, verify it is valid OpenAPI/Swagger (.json/.yaml with openapi/swagger field) or a Postman collection export.
  3. Rename/re-export the spec so its format is detectable, or wrap single files in a directory.

Example fix

# before
strix -n -t ./openapi-export.txt   # exists but not a recognized spec

# after
strix -n -t ./openapi-export.json  # valid OpenAPI document
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

p = Path(target).expanduser()
if p.exists() and not p.is_dir():
    # only spec files are accepted as files
    if p.suffix.lower() not in {".json", ".yaml", ".yml"}:
        target = str(p.parent)  # scan the containing project directory instead

Type guard

from strix.interface.utils import detect_spec_format

def is_acceptable_file_target(p: Path) -> bool:
    return p.is_file() and detect_spec_format(p) is not None

Try / catch

try:
    ttype, details = infer_target_type(target)
except ValueError as e:
    if "not a directory" in str(e):
        ttype, details = infer_target_type(str(Path(target).expanduser().parent))
    else:
        raise

Prevention

When it happens

Trigger: infer_target_type('./notes.txt') where notes.txt exists but is not OpenAPI JSON/YAML or a Postman collection; pointing -t at a symlink to a regular file of an unsupported type; a directory path that actually resolves to a file.

Common situations: Typo where the user meant the parent directory but hit a file inside it; expecting any file to be scanned as 'local code' (Strix only takes directories for that); an export that produced a .yaml that is not actually an OpenAPI document, so detect_spec_format returns None.

Related errors


AI-assisted analysis of usestrix/strix@8551339130 (2026-08-15). Data as JSON: /api/errors/997b11129760295f. Report an issue: GitHub.