Skip to content

work-items: gitea create-item.sh label paging continues past a malformed page instead of breaking, unlike every sibling jq 'length' call #3484

Description

@kyle-sexton

Found by the repo-wide /code-tidying:batch-simplify sweep (group G67). Reported, not fixed — the sweep is behavior-preserving.

What happens

plugins/work-items/tools/work-item-tracker/adapters/gitea/create-item.sh:124 reads:

(($(jq 'length' <<<"$WIT_GITEA_BODY") < WIT_GITEA_PAGE_SIZE)) && break

Unlike every sibling jq 'length' call in this adapter, this one has neither 2>/dev/null nor a numeric fallback. The siblings that do:

  • create-item.sh:118
  • create-item.sh:145
  • common.sh:463
  • list-items.sh:79

Why it matters

On a non-array body, jq errors and the command substitution yields the empty string. Bash then evaluates (( < 50 )), which is an arithmetic syntax error: it prints to stderr, returns 1, and — because this is the && side of a short-circuit — the break never fires. The paging loop continues rather than stopping.

Two consequences: extra API requests against Gitea for pages the adapter has already decided it cannot parse, and a wrong truncation verdict, since the loop's exit condition is what determines whether the label set was fully walked. A stderr arithmetic error is also a poor diagnostic for "the API returned something that is not a list".

Suggested direction

Match the sibling form already used four times in the same adapter — 2>/dev/null plus a numeric fallback — so a malformed page produces a definite number rather than an empty expansion. Worth deciding deliberately whether the right fallback is 0 (treat as a short page, break, report truncation) or a loud failure, since the two differ in whether a malformed page silently ends the walk or aborts the operation. The surrounding code's fail-loud posture on checked reads suggests the latter deserves consideration.

Fixing this changes behavior on the malformed-response path, which is why the sweep left it alone.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions