Hmbown/CodeWhale · error · ValueError

PENDING_GROUPS may contain string literals only

Error message

PENDING_GROUPS may contain string literals only

What it means

After stripping all string literals from the PENDING_GROUPS array body, load_pending_groups requires only whitespace and commas to remain. If any other token survives, the array contains non-literal elements (expressions, constants, comments interfering, or malformed syntax) that the manifest checker cannot safely treat as a plain list of command names, so it raises ValueError.

Solutions

  1. Inspect PENDING_GROUPS and replace any non-literal entries with plain string literals
  2. Remove stray code or unstripped comments from inside the array brackets
  3. Generate the literal list (e.g. via a small macro expansion or manually) instead of building it at compile time
  4. If the format must change, update load_pending_groups' validation accordingly

Example fix

// before
pub(crate) const PENDING_GROUPS: &[&str] = &[GROUP_A, "cmd_b"];
// after
pub(crate) const PENDING_GROUPS: &[&str] = &["cmd_a", "cmd_b"];
Defensive patterns

Strategy: validation

Validate before calling

body = re.search(r'=\s*&\[(.*?)\];', src, re.DOTALL).group(1)
stripped = re.sub(r'"(?:\\.|[^"\\])*"', "", body)
assert re.fullmatch(r"[\s,]*", stripped), "non-literal inside PENDING_GROUPS"

Try / catch

try:
    pending = load_pending_groups(path)
except ValueError as exc:
    print(f"PENDING_GROUPS must be plain literals: {exc}")
    sys.exit(1)

Prevention

When it happens

Trigger: Running the checker when PENDING_GROUPS contains items like other constants (e.g. include! or concatenation), doc comments inside the array that aren't stripped, escaped/odd tokens, or trailing code accidentally left inside the brackets.

Common situations: A developer added a helper const or format expression into the array instead of a plain string literal; a macro invocation was used to build the list; an editing mistake left stray code inside the array body.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/c07123f507cc00f6. Report an issue: GitHub.

Appendix: source

Thrown at scripts/check-command-migration-manifest.py:477

def load_topology(path: Path = TOPOLOGY_PATH) -> dict:
    with path.open(encoding="utf-8") as fh:
        return json.load(fh)


def load_pending_groups(path: Path = CONTRACT_PATH) -> list[str]:
    """Read the TUI frontier projection from `PENDING_GROUPS` fail-closed."""
    source = path.read_text(encoding="utf-8")
    match = re.search(
        r"pub\(crate\)\s+const\s+PENDING_GROUPS\s*:\s*&\[&str\]\s*=\s*&\[(.*?)\];",
        source,
        re.DOTALL,
    )
    if match is None:
        raise ValueError(f"could not locate PENDING_GROUPS in {path}")
    body = match.group(1)
    stripped = re.sub(r'"(?:\\.|[^"\\])*"', "", body)
    if re.fullmatch(r"[\s,]*", stripped) is None:
        raise ValueError("PENDING_GROUPS may contain string literals only")
    return re.findall(r'"((?:\\.|[^"\\])*)"', body)


def validate_pending_projection(doc: dict, pending: list[str]) -> list[ManifestViolation]:
    if pending != doc.get("frontier"):
        return [ManifestViolation(
            "frontier-projection",
            "PENDING_GROUPS",
            f"TUI projection {pending!r} does not equal JSON frontier {doc.get('frontier')!r}",
        )]
    return []


def load_topology_at_ref(ref: str, root: Path = REPO_ROOT) -> dict | None:
    """Load the topology from a Git revision; return None before its introduction."""
    commit = subprocess.run(
        ["git", "rev-parse", "--verify", f"{ref}^{{commit}}"],
        cwd=root,

View on GitHub (pinned to 433685b202)