Skip to content

Reject --sort-by where the API has no sortBy parameter - #10

Merged
arcaputo3 merged 1 commit into
chore-precommit-golangci-systemfrom
gh-4-sort-by-loud-failure
Aug 5, 2026
Merged

Reject --sort-by where the API has no sortBy parameter#10
arcaputo3 merged 1 commit into
chore-precommit-golangci-systemfrom
gh-4-sort-by-loud-failure

Conversation

@arcaputo3

Copy link
Copy Markdown
Contributor

Closes #4. Stacked on #9 (review the second commit only).

What the API actually does

Verified against the live API rather than inferred:

Request Result
/events?sortBy=bogus 400 — sortBy must be one of the following values: id, date
/documents/transcripts?sortBy=date 400 — property sortBy should not exist
/documents/transcripts?direction=desc 200, and it does reverse the order

So /events is the only list endpoint with a sortBy parameter, and its enum is id, date. The issue reports the flag as "silently dropped" — it is: toParams gates every parameter on a per-resource allow-list and sortBy is only in the events set, so the flag never reaches the wire and nothing complains.

That silence is the whole bug. Document endpoints return rows in insertion order, so transcripts list --tickers X --sort-by date --direction desc yields the oldest transcripts on page one, looking exactly like a correct answer.

Change

  • resource.sortFields records the accepted enum per resource; only events has one.
  • validateSortBy rejects an unknown field on events, and any --sort-by on a resource that cannot sort, before any request goes out.
  • Usage failures now exit 2 (new usageError type, mapped in Run) so scripts can tell a bad command line from a failed request.
  • pages/chapters reject --sort-by too — they inherit the shared list flags but sort by nothing.
  • The error and --help share one recipe paragraph, so they cannot drift apart.

--direction is deliberately untouched: it is accepted everywhere and works, it just reverses insertion order rather than date order. The message says so, since that distinction is what makes the flag misleading.

$ quartr transcripts list --tickers AAPL --sort-by date
--sort-by is not supported by `quartr transcripts list`: the Quartr endpoint has no
sortBy parameter, so rows come back in insertion order and the newest items may be
missing from the first page.

Sort events first, then fetch by event id:
  quartr events list --tickers AAPL --sort-by date --direction desc --limit 5
  quartr transcripts list --event-ids <id>

`--direction asc|desc` is accepted here, but it reverses insertion order, not date order.
$ echo $?
2

On companies list, where --event-ids does not exist, the recipe collapses to "only events list supports --sort-by".

Tests

Four cases: rejection on an unsortable resource (asserting no HTTP request is made), unknown field on events, sortBy/direction still forwarded for a valid events sort, and rejection on pages.

🤖 Generated with Claude Code

Only /events accepts sortBy (enum: id, date — confirmed against the live
API). Everywhere else the CLI's allow-list dropped the flag before building
the request, and those endpoints return rows in insertion order, so a caller
who passed --sort-by date got the oldest documents on page one with no
indication anything had gone wrong.

Add sortFields to the resource table and validate against it. An unknown
field on events, or any --sort-by on a resource that cannot sort, now exits 2
and points at the events-first recipe. --direction is left alone: every list
endpoint accepts it, it just reverses insertion order rather than date order.

Closes #4

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@arcaputo3
arcaputo3 merged commit ad694a1 into main Aug 5, 2026
1 check passed
Sign up for free to 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.

list: --sort-by/--direction silently dropped on reports/slides/transcripts (latest documents missing from first page)

1 participant