From 342d9ca9f4ced5d51aa089d5a7f9a3120eba8cd5 Mon Sep 17 00:00:00 2001 From: "posthog-eu[bot]" <226701856+posthog-eu[bot]@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:26:51 +0000 Subject: [PATCH] fix(cli): throw CliUserError from login expected failures 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 --- cli/src/login.ts | 4 ++-- cli/test/test-posthog-exception.mjs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/src/login.ts b/cli/src/login.ts index adb7690c6c..d8b4679d4d 100644 --- a/cli/src/login.ts +++ b/cli/src/login.ts @@ -36,7 +36,7 @@ export async function loginInternal(apikey: string, options: Options, silent = f if (!apikey) { if (!silent) log.error('Missing API key, you need to provide an API key to upload your bundle') - throw new Error('Missing API key') + throw new CliUserError('Missing API key') } if (!silent) @@ -47,7 +47,7 @@ export async function loginInternal(apikey: string, options: Options, silent = f if (local && !existsSync('.git')) { if (!silent) log.error('To use local you should be in a git repository') - throw new Error('Not in a git repository') + throw new CliUserError('Not in a git repository') } // Validate, persist (0o600) and emit the login event via the shared auth core. diff --git a/cli/test/test-posthog-exception.mjs b/cli/test/test-posthog-exception.mjs index ed890c0d93..39303e7bc0 100644 --- a/cli/test/test-posthog-exception.mjs +++ b/cli/test/test-posthog-exception.mjs @@ -217,6 +217,9 @@ try { // never opens an error tracking issue. assert.equal(shouldCapturePosthogException(new CliUserError('Login cancelled')), false) assert.equal(shouldCapturePosthogException(new CliUserError('Upload cancelled by user')), false) + // `login --local` outside a git repository is a normal user mistake the CLI + // already handles cleanly, so it throws CliUserError and never opens an issue. + assert.equal(shouldCapturePosthogException(new CliUserError('Not in a git repository')), false) // Two failures on different channels must be treated identically (one issue, // not one per channel), since the channel name lives in context, not the message. assert.equal(