can1357/oh-my-pi · error · ValueError

invalid state: {state!r}

Error message

invalid state: {state!r}

What it means

ValueError from list_issues when the `state` argument is not exactly one of "open", "closed", or "all". It is a client-side validation guard run before any HTTP request.

Source

Thrown at python/robomp/src/github_client.py:537

            if len(batch) < 100:
                return files
            page += 1

    async def list_issues(
        self,
        repo: str,
        *,
        state: str = "open",
        limit: int = 30,
    ) -> list[IssueSummary]:
        """List recent issues for `repo`, newest-updated first. Excludes pull requests.

        `state` is one of `open`, `closed`, `all`. `limit` is capped at 100 by the
        GitHub `per_page`; we don't paginate here — the dashboard browse view shows
        a recent slice, not every issue ever.
        """
        if state not in ("open", "closed", "all"):
            raise ValueError(f"invalid state: {state!r}")
        per_page = max(1, min(int(limit), 100))
        data = await self.request(
            "GET",
            f"/repos/{repo}/issues",
            params={"state": state, "per_page": per_page, "sort": "updated", "direction": "desc"},
        )
        out: list[IssueSummary] = []
        for item in data or []:
            if "pull_request" in item:
                continue  # GitHub's /issues endpoint also returns PRs; skip them.
            out.append(_summary_from_item(repo, item))
        return out

    async def search_issues(self, repo: str, query: str, *, limit: int = 10) -> list[IssueSummary]:
        """Search issues AND pull requests in `repo` using GitHub issue-search syntax.

        `query` takes bare keywords plus qualifiers (`is:pr`, `is:closed`,
        `label:bug`, `in:title`, …); the `repo:` scope is applied here. Results

View on GitHub (pinned to 9690622007)

Solutions

  1. Pass exactly "open", "closed", or "all" (lowercase)
  2. Normalize/whitelist the value before calling list_issues

Example fix

// before
issues = await client.list_issues(repo, state="opened")
// after
issues = await client.list_issues(repo, state="open" if state == "opened" else state)
Defensive patterns

Strategy: validation

Validate before calling

VALID_STATES = {"open", "closed", "all"}
if state not in VALID_STATES:
    raise ValueError(f"state must be one of {sorted(VALID_STATES)}, got {state!r}")

Prevention

When it happens

Trigger: Passing states like "Open", "OPEN", "opened", None, or other arbitrary strings to list_issues.

Common situations: Mapping a UI dropdown or config value straight into the API param; upstream code using a different issue-state vocabulary (e.g. "opened" from webhook payloads).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/eb21a58aa5e0a9dc. Report an issue: GitHub.