Skip to content

fix(api): handle GraphQL partial-success responses cleanly (CRY-61) - #150

Merged
bougyman merged 2 commits into
mainfrom
CRY-61-clean-graphql-not-found-errors
Aug 18, 2026
Merged

fix(api): handle GraphQL partial-success responses cleanly (CRY-61)#150
bougyman merged 2 commits into
mainfrom
CRY-61-clean-graphql-not-found-errors

Conversation

@bougyman

Copy link
Copy Markdown
Member

Summary

  • Root cause: Api.handle_response/1 checked "errors" before "data", so Linear's entity-not-found response (HTTP 200 with both "data": {"issue": null} and "errors": [{"type": "ENTITY_NOT_FOUND"}]) returned {:error, {:graphql_errors, ...}} — bypassing fetch_one/1's existing nil-data handler and falling through to the "What the heck is this?" catch-all.
  • Fix: Reorder handle_response/1 to check "data" first. A response with both keys is a GraphQL partial-success; callers already handle nil fields (fetch_one/1's {:not_found, id} clause), so they now see {:ok, data} and produce a clean exit-66 message.
  • Safety net: Added a handle_error/3 clause for graphql errors that reach cli.ex without being converted (errors-only responses, no "data" key) — prints the API's own error message instead of the opaque fallback.

Test plan

  • mix test — all new tests pass, no regressions (272/278; 6 pre-existing git test failures unrelated to this change)
  • mix compile --warnings-as-errors — clean
  • mix credo — no issues
  • New unit test: Api.call with partial-success response returns {:ok, data} (api_test.exs)
  • New unit test: Linear.issues/1 with ENTITY_NOT_FOUND response normalises to {:not_found, id} (issue_test.exs)
  • New integration test: issue develop with ENTITY_NOT_FOUND exits 66 with clean message, not "WTH" (cli_test.exs)
  • New integration test: errors-only GraphQL response prints API message, not "WTH" (cli_test.exs)

Closes CRY-61

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings August 18, 2026 23:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

bougyman and others added 2 commits August 18, 2026 19:57
Linear returns HTTP 200 with both "data" and "errors" when an entity is
not found. Previously Api.handle_response/1 matched "errors" first and
returned {:error, {:graphql_errors, ...}}, which fell through to the
opaque "What the heck is this?" catch-all in CLI.handle_error/3.

Fix by matching "data" before "errors" in handle_response/1: a response
with both keys is a partial-success — the query ran, some fields are
nil. Callers already handle nil fields (fetch_one/1's {:not_found, id}
clause), so they now receive {:ok, data} and produce a clean exit-66
message instead of the crash-style fallback.

Add a safety-net handle_error/3 clause for graphql_errors that do reach
cli.ex (errors-only responses, no "data" key) — prints the API's own
error message instead of "What the heck is this?".

Closes CRY-61.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bougyman
bougyman force-pushed the CRY-61-clean-graphql-not-found-errors branch from d9f4e90 to 959c975 Compare August 18, 2026 23:57
@bougyman
bougyman merged commit 21d0363 into main Aug 18, 2026
2 checks passed
@bougyman
bougyman deleted the CRY-61-clean-graphql-not-found-errors branch August 18, 2026 23:59
bougyman pushed a commit that referenced this pull request Aug 19, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.15.0](v1.14.0...v1.15.0)
(2026-08-19)


### Features

* **issue:** add --status/-s to assign and take
([#151](#151))
([537f54b](537f54b))


### Bug Fixes

* **api:** handle GraphQL partial-success responses cleanly (CRY-61)
([#150](#150))
([21d0363](21d0363))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants