Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,9 +1177,12 @@ export function findSavedKey(quiet = false) {
key = readFileSync(keyPath, 'utf8').trim()
}
if (!key) {
const message = `Cannot find API key in local folder or global, please login first with ${getPMAndCommand().runner} @capgo/cli login`
// Keep this message static (no interpolated package-manager runner): it is a
// CliUserError so error tracking skips it, and a constant string means one
// "not logged in" condition renders as one value instead of one per runner.
const message = 'Cannot find API key in local folder or global, please login first with `capgo login`'
log.error(message)
throw new Error(message)
throw new CliUserError(message)
}
return key
}
Expand Down
23 changes: 23 additions & 0 deletions cli/test/test-posthog-exception.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ try {
'Cannot upload <cwd>/<path> for <email> app <app_id> --token <redacted>',
)

// Two occurrences of the SAME logical error but with different minified top
// frames (as different builds / call sites produce) must share one fingerprint.
requests.length = 0
const minifiedA = new Error('boom')
minifiedA.stack = `Error: boom\n at T0 (${cwd()}/dist/index.js:1:20)`
const minifiedB = new Error('boom')
minifiedB.stack = `Error: boom\n at CDA (${cwd()}/dist/chunk-2.js:9:3)`
for (const minified of [minifiedA, minifiedB]) {
await capturePosthogException({
error: minified,
functionName: 'bundle upload',
kind: 'unhandled_error',
status: 1,
})
}
assert.equal(requests.length, 2)
const [fpA, fpB] = requests.map(r => JSON.parse(r.init.body).properties.$exception_fingerprint)
assert.equal(fpA, fpB)
assert.equal(fpA, 'bundle upload:unhandled_error:Error:1')

requests.length = 0
await capturePosthogException({
error: undefined,
Expand Down Expand Up @@ -146,6 +166,9 @@ try {
// regardless of the (dynamic) channel context attached to them.
assert.equal(shouldCapturePosthogException(new CliUserError('Channel does not have a bundle linked', { appId: 'com.example.app', channel: 'production' })), false)
assert.equal(shouldCapturePosthogException(new CliUserError('Missing API key')), false)
// `findSavedKey` throws this as a CliUserError when nobody ran `capgo login`;
// it must be skipped (a plain Error with this text would have leaked through).
assert.equal(shouldCapturePosthogException(new CliUserError('Cannot find API key in local folder or global, please login first with `capgo login`')), false)
// `uploadFail` now throws CliUserError, so a duplicate-version upload — a normal
// `bundle upload` outcome — is filtered out of error tracking by type.
assert.equal(shouldCapturePosthogException(new CliUserError('Version 1.2.3 already exists')), false)
Expand Down
Loading