fix(cli): throw CliUserError from login expected failures

Draft
PO
2mo ago
+5-2

Summary

  • Who is hurt: the team, not users. login --local outside a git repo, and login with no API key, are normal user mistakes the CLI already handles — a clear message and a non-zero exit. But each opened an error tracking $exception issue that someone has to triage and close by hand.
  • Root cause: cli/src/login.ts threw a bare throw new Error(...) at the git-repo check (Not in a git repository) and the missing-key check (Missing API key). shouldCapturePosthogException only skips CliUserError instances and a short marker list, so neither message was skipped.
  • Fix: swap both to new CliUserError(...), the marker shouldCapturePosthogException already skips by type. The cancel path one block up already uses it, and the import was already present. Message strings stay constant (no interpolation), per the CliUserError doc comment.

Same pattern as the in-flight #2954 (bundle/zip.ts) and #2955 (bundle/partial.ts). Neither touches the login path, so this is a clean, non-overlapping follow-up.

Site (login.ts)MessageTrigger
Missing-key checkMissing API keylogin with no API key
Git-repo checkNot in a git repositorylogin --local outside a git repo

User-facing behavior is unchanged: both sites still print their message (To use local you should be in a git repository) and exit non-zero. Exit codes and trackCommandFailed failure analytics stay intact; only the $exception capture goes away.

Test plan

  • bun test/test-posthog-exception.mjs — passes, extended to assert Not in a git repository is skipped (the Missing API key case was already covered).
  • bun run lint and bun run typecheck in cli/ — clean.

Screenshots

Checklist

  • My code follows the code style of this project and passes
    bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation
    accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce
    my tests

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.