pytorch/pytorch · error · ValueError

{codeowners}:{line_number}: invalid taxonomy entry

Error message

{codeowners}:{line_number}: invalid taxonomy entry

What it means

Thrown by parse_patterns in scripts/codeowners/check_taxonomy.py when a line inside the taxonomy section is neither a '# [group]' header, a '# /path' draft entry or '/path' active entry, nor a plain comment/blank. I.e. the line has content, does not start with '#', and does not start with '/' or '# /' — the parser has no category for it, so it rejects it with the file:line location.

Source

Thrown at scripts/codeowners/check_taxonomy.py:121

                owners = []
                for field in fields[1:]:
                    if field.startswith("#"):
                        break
                    owners.append(field)
                if not owners:
                    raise ValueError(f"{location}: active pattern has no owners")
                invalid_owners = [
                    owner for owner in owners if not is_valid_owner(owner)
                ]
                if invalid_owners:
                    raise ValueError(
                        f"{location}: invalid active owners: {', '.join(invalid_owners)}"
                    )
            if pattern == "/" or any(character in pattern for character in "*?[\\"):
                raise ValueError(f"{location}: invalid taxonomy path: {pattern!r}")
            patterns.append(TaxonomyPattern(group, pattern[1:], line_number))
        elif line and not line.startswith("#"):
            raise ValueError(f"{codeowners}:{line_number}: invalid taxonomy entry")

    if not patterns:
        raise ValueError("taxonomy section contains no patterns")
    return patterns, section_groups


def tracked_paths(repo: Path) -> list[str]:
    """List paths committed in HEAD, including submodule entries."""
    output = subprocess.run(
        ["git", "-C", repo, "ls-tree", "-r", "-z", "--name-only", "HEAD"],
        check=True,
        capture_output=True,
    ).stdout.decode()
    return sorted(path for path in output.split("\0") if path)


def analyze(paths: list[str], patterns: list[TaxonomyPattern]) -> Report:
    """Measure coverage and verify that source order preserves specificity."""

View on GitHub (pinned to dcd2ecae77)

Solutions

  1. Prefix the line with '#' so it is treated as a comment, if it is a note
  2. Remove the line if it is stray content or conflict markers
  3. Move misplaced real CODEOWNERS content to the correct section outside the taxonomy markers

Example fix

# before (inside taxonomy section)
NOTE: discuss with ops
# after
# NOTE: discuss with ops
Defensive patterns

Strategy: validation

Validate before calling

def stray_lines_in_section(path: str) -> list[str]:
    lines = open(path).read().splitlines()
    start = lines.index("# Draft grouped review-surface definitions:") + 1
    bad = []
    for i, line in enumerate(lines[start:], start + 1):
        s = line.strip()
        if s and not s.startswith("#") and not s.startswith("/"):
            bad.append(f"{i}: {s}")
    return bad

Prevention

When it happens

Trigger: Leaving actual prose text or a raw owner list in the taxonomy section, e.g. a line 'owned by release team'. A line starting with text like 'NOTE: check with ops'. Any non-comment, non-path token inside the section boundaries.

Common situations: Editing CODEOWNERS and leaving notes inside the taxonomy section instead of as '#' comments. Merge-conflict markers ('<<<<<<< HEAD') surviving inside the section. Paste accidents.

Related errors


AI-assisted analysis of pytorch/pytorch@dcd2ecae77 (2026-08-14). Data as JSON: /api/errors/abf7043f6e31b357. Report an issue: GitHub.