Skip to content

fix(cli): announce truncated structured list pages on stderr - #169

Merged
ysyneu merged 2 commits into
mainfrom
fix/list-projection-exit-code
Aug 27, 2026
Merged

fix(cli): announce truncated structured list pages on stderr#169
ysyneu merged 2 commits into
mainfrom
fix/list-projection-exit-code

Conversation

@ysyneu

Copy link
Copy Markdown
Contributor

What

In json/toon mode, PrintList suppresses the "Showing N results (page P, total T)." footer to keep stdout byte-pure for jq/toon pipelines. That left a gap: a page short of the server-reported total (e.g. the default --limit 20 of a far larger total) looked exactly like the whole set to anything reading stdout.

PrintList now prints a note: showing N of T total results (page P); raise --limit or use --page for the rest line on stderr when the page doesn't cover the total — same pattern as the existing projection notes. Table mode is unchanged (it keeps the stdout footer); a page that covers the total prints nothing extra. This covers every paged list command that goes through PrintList (alert list, alert-event list, incident list, change list, audit search, insight incident-list).

Overflow hard-failure is now pinned by tests

A compact list projection that can't fit its 16 KiB budget already fails the command (the error propagates out of RunEmain exits 1 with Error: projected list is … on stderr and nothing on stdout). That behavior had no command- or binary-level coverage, so this adds:

  • TestCommandListProjectionOverflowFails (incident list + alert-event list): irreducible projection → Execute returns the byte-limit refusal and stdout stays empty.
  • TestProjectionOverflowFailsHard (built binary against a stub server): non-zero exit code, empty stdout, refusal on stderr — so a pipeline reading stdout sees a failed call, never an empty page masquerading as "no data".
  • TestCommandAlertListStructuredAnnouncesTruncation: the new stderr note fires on a truncated structured page, stays silent when the page covers the total, and table mode keeps its stdout footer.

Verification

  • make check (gofmt/gci, golangci-lint, go test -race ./..., build): all green.
  • End-to-end with the built binary against a stub server: structured truncated page → exit 0, parseable stdout, note on stderr; table mode → stdout footer, no stderr note; over-budget projection → exit 1, empty stdout, Error: projected list is … exceeds the 16384-byte limit on stderr.

In json/toon mode PrintList suppresses the "Showing N results" footer to
keep stdout byte-pure for pipelines, so a page short of the server total
(e.g. the default --limit 20 of a much larger total) was indistinguishable
from the whole set. PrintList now prints a "note: showing N of T total
results (page P)" line on stderr when the page does not cover the total;
table mode is unchanged.
Also pin, at both the command and the built-binary level, that a compact
list projection which cannot fit its byte budget fails hard: non-zero exit,
the refusal on stderr, and nothing on stdout — so a pipeline reading stdout
sees a failed call rather than an empty page.
The note fired whenever total > count, which misjudges the last page:
--limit 20 --page 2 against a total of 40 printed "use --page for the
rest" even though page 2 is the end. PrintList now takes the page size
and computes hasMore as (page-1)*limit+count < total, so the note only
appears when rows actually remain beyond the current page.
@ysyneu
ysyneu changed the base branch from feat/ai-sre to mainAugust 27, 2026 01:55
@ysyneu
ysyneu merged commit 592cc71 into mainAug 27, 2026
12 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@ysyneu