Skip to content

fix: give a clear message and exit 78 when LINEAR_API_KEY is missing - #86

Merged
bougyman merged 1 commit into
mainfrom
issue-74
Aug 12, 2026
Merged

fix: give a clear message and exit 78 when LINEAR_API_KEY is missing#86
bougyman merged 1 commit into
mainfrom
issue-74

Conversation

@bougyman

Copy link
Copy Markdown
Member

Summary

Closes #74. A missing LINEAR_API_KEY previously surfaced as a raw %Ash.Error.Unknown{} dump reaching the generic catch-all handler ("What the heck is this?" + a full Ash stacktrace) - the Ash manual actions wrapping LinearCli.Api.call/2's {:error, :missing_api_key} produced a shape that didn't match either existing specific handle_error/3 clause.

Adds a clause matching that exact wrapped shape (Ash stringifies the original reason into UnknownError's :error field rather than preserving the atom - verified directly, not guessed) and prints a clear, actionable message instead, with sysexits.h's EX_CONFIG (78) since this is a configuration problem, not a crash. Plain pattern match, no guard, so it degrades gracefully to the existing catch-all if Ash's wrapping format ever changes rather than introducing a new failure mode.

Test plan

  • Reproduced the original bug exactly (env -u LINEAR_API_KEY mix run -e 'LinearCli.CLI.main(["issue", "list"])') before fixing, confirmed the fix resolves it after
  • New test (missing_api_key_test.exs, async: false mirroring LinearCli.ApiTest's existing env-var-unset pattern) - clear message, exit 78, no raw Ash dump
  • mix test - no regressions (14 pre-existing GPG/pinentry sandbox failures reproduce identically on a clean stash of this branch, unrelated)
  • mix format --check-formatted clean

🤖 Generated with Claude Code

A missing LINEAR_API_KEY previously surfaced as a raw
%Ash.Error.Unknown{} dump reaching the generic catch-all handler ("What
the heck is this?" + a full Ash stacktrace) - the Ash manual actions
wrapping LinearCli.Api.call/2's {:error, :missing_api_key} produced a
shape that didn't match either existing specific handle_error/3 clause.

Adds a clause matching that exact wrapped shape (Ash stringifies the
original reason into UnknownError's :error field rather than
preserving the atom - verified directly, not guessed) and prints a
clear, actionable message instead, with sysexits.h's EX_CONFIG (78)
since this is a configuration problem, not a crash. Plain pattern
match, no guard, so it degrades gracefully to the existing catch-all if
Ash's wrapping format ever changes rather than introducing a new
failure mode.

Closes #74.
Copilot AI lite review requested due to automatic review settings August 12, 2026 18:19

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.

Pull request overview

Improves the CLI’s UX when LINEAR_API_KEY is missing by intercepting the specific Ash-wrapped “missing api key” error shape and emitting a clear, actionable configuration message while exiting with EX_CONFIG (78), instead of falling through to the generic “What the heck is this?” handler.

Changes:

  • Add a dedicated handle_error/3 clause for the Ash %Ash.Error.Unknown{...} shape produced when LinearCli.Api.call/2 returns {:error, :missing_api_key}.
  • Print a targeted message (with a settings URL) and exit 78 for missing configuration.
  • Add an async: false regression test that unsets/restores LINEAR_API_KEY and asserts on stderr output + exit code.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
app/lib/linear_cli/cli.ex Adds a specific error handler for the “missing API key” Ash error wrapper and exits with 78 + friendly guidance.
app/test/linear_cli/cli/missing_api_key_test.exs Adds a non-async test ensuring the CLI prints the friendly message and exits 78 when LINEAR_API_KEY is unset.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bougyman
bougyman merged commit c5b9ec1 into main Aug 12, 2026
3 checks passed
@bougyman
bougyman deleted the issue-74 branch August 12, 2026 18:24
This was referenced Aug 12, 2026
bougyman pushed a commit that referenced this pull request Aug 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.2.0](v1.1.1...v1.2.0)
(2026-08-12)


### Features

* add a root-level repo-management Mix project (mix
container.build/publish)
([#84](#84))
([9d0b730](9d0b730))


### Bug Fixes

* give a clear message and exit 78 when LINEAR_API_KEY is missing
([#86](#86))
([c5b9ec1](c5b9ec1))

---
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.

Don't fail miserably when there's no LINEAR_API_KEY available. Be nice.

2 participants