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(