fix(cli): throw CliUserError from login expected failures - #2956
Draft
posthog-eu[bot] wants to merge 1 commit into
Draft
fix(cli): throw CliUserError from login expected failures#2956posthog-eu[bot] wants to merge 1 commit into
posthog-eu[bot] wants to merge 1 commit into
Conversation
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
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
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.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.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.login.ts)Missing API keyloginwith no API keyNot in a git repositorylogin --localoutside a git repoUser-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 andtrackCommandFailedfailure analytics stay intact; only the$exceptioncapture 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
bun run lint:backend && bun run lint.accordingly.
my tests
Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.