fix(cli): throw CliUserError from login expected failures
Draft
PO
2mo ago+5+5+0123456789-2-2-0123456789
Summary
- Who is hurt: the team, not users.
login --localoutside a git repo, andloginwith 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$exceptionissue that someone has to triage and close by hand. - Root cause:
cli/src/login.tsthrew a barethrow new Error(...)at the git-repo check (Not in a git repository) and the missing-key check (Missing API key).shouldCapturePosthogExceptiononly skipsCliUserErrorinstances and a short marker list, so neither message was skipped. - Fix: swap both to
new CliUserError(...), the markershouldCapturePosthogExceptionalready 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 theCliUserErrordoc 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) | Message | Trigger |
|---|---|---|
| Missing-key check | Missing API key | login with no API key |
| Git-repo check | Not in a git repository | login --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 assertNot in a git repositoryis skipped (theMissing API keycase was already covered).bun run lintandbun run typecheckincli/— 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.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.