usestrix/strix · error · ValueError

Target list file '{path_str}' must be valid UTF-8 text: {e!s

Error message

Target list file '{path_str}' must be valid UTF-8 text: {e!s}

What it means

Raised when the target list file's bytes are not valid UTF-8 — path.read_text(encoding='utf-8') raises UnicodeDecodeError, which is caught and re-raised as ValueError with the decoder's message. Strix requires UTF-8 because the file is parsed line-by-line into target strings.

Source

Thrown at strix/interface/utils.py:1225


def read_target_list_file(path_str: str) -> list[str]:
    """Read scan targets from a file, one target per non-empty, non-comment line."""
    if not path_str or not path_str.strip():
        raise ValueError("--target-list path must not be empty.")

    path = Path(path_str).expanduser()
    if not path.is_file():
        raise ValueError(f"Target list file '{path_str}' is not an existing file.")

    try:
        targets = [
            target
            for line in path.read_text(encoding="utf-8").splitlines()
            if (target := line.strip()) and not target.startswith("#")
        ]
    except UnicodeDecodeError as e:
        raise ValueError(f"Target list file '{path_str}' must be valid UTF-8 text: {e!s}") from e
    except OSError as e:
        raise ValueError(f"Failed to read target list file '{path_str}': {e!s}") from e

    targets = [target for target in targets if target]
    if not targets:
        raise ValueError(f"Target list file '{path_str}' is empty.")
    return targets


def sanitize_name(name: str) -> str:
    sanitized = re.sub(r"[^A-Za-z0-9._-]", "-", name.strip())
    return sanitized or "target"


def derive_repo_base_name(repo_url: str) -> str:
    if repo_url.endswith("/"):
        repo_url = repo_url[:-1]

View on GitHub (pinned to 8551339130)

Solutions

  1. Re-save the file as UTF-8 (e.g. in PowerShell: Get-Content old.txt | Set-Content -Encoding utf8 targets.txt).
  2. Check the first bytes: file targets.txt or xxd targets.txt | head — a UTF-16 BOM (FF FE) confirms the encoding issue.
  3. Remove non-ASCII characters from target lines, which are rarely valid in URLs/paths anyway.

Example fix

# PowerShell - before
"https://a.com" | Out-File targets.txt            # UTF-16

# PowerShell - after
"https://a.com" | Out-File targets.txt -Encoding utf8
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def is_utf8_text_file(p: str) -> bool:
    try:
        Path(p).read_text(encoding="utf-8")
        return True
    except UnicodeDecodeError:
        return False

if not is_utf8_text_file(path_str):
    raise SystemExit(f"{path_str} is not UTF-8; re-save it (PowerShell: -Encoding utf8)")

Try / catch

try:
    targets = read_target_list_file(path_str)
except ValueError as e:
    if "must be valid UTF-8" in str(e):
        raise SystemExit("Re-save the target list as UTF-8 (watch for PowerShell UTF-16 output).") from e
    raise

Prevention

When it happens

Trigger: A targets file saved as UTF-16 (common for files created via PowerShell redirection, e.g. Out-File without -Encoding utf8), Latin-1 with high bytes, or binary garbage at the given path.

Common situations: Windows PowerShell '>`' redirection producing UTF-16 LE files with a BOM; editors saving in a legacy codepage; accidentally pointing --target-list at a binary file.

Related errors


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