Skip to content

fix(cli): throw CliUserError from login expected failures - #2956

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-throw-cliusererror-from-login-feb76c
Draft

fix(cli): throw CliUserError from login expected failures#2956
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-throw-cliusererror-from-login-feb76c

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

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

Review in cubic

The `login --local` git-repo check and the missing-key check threw a bare
`Error`, so `shouldCapturePosthogException` never skipped them and each opened
an error tracking `$exception` issue. Both are normal user mistakes the CLI
already handles cleanly. Swap them to `CliUserError`, which that function
skips by type, keeping the exit code and `trackCommandFailed` analytics intact.

Generated-By: PostHog Code
Task-Id: 6fb16c94-eadb-4faa-acec-420122cd48b6
@codspeed-hq

codspeed-hq Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing posthog-self-driving/fixcli-throw-cliusererror-from-login-feb76c (342d9ca) with main (b62668a)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sonarqubecloud

sonarqubecloud Bot commented Aug 9, 2026

Copy link
Copy Markdown

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.

0 participants