fix(cli): classify auth failures by type, not message text - #2972
Draft
posthog-eu[bot] wants to merge 2 commits into
Draft
fix(cli): classify auth failures by type, not message text#2972posthog-eu[bot] wants to merge 2 commits into
posthog-eu[bot] wants to merge 2 commits into
Conversation
Convert the bad-key throw in `resolveUserIdFromApiKey` and the RBAC throw in `checkAppExistsAndHasPermissionOrgErr` from plain `Error` to `CliUserError`, so `shouldCapturePosthogException` skips them by type. A later reword of either message can no longer silently break the error-tracking filter, and the RBAC app id and permission key move into `CliUserError` context so error tracking maps every app to one issue instead of one per app. Generated-By: PostHog Code Task-Id: ab1dbac6-b0af-45ff-980a-8fd68253b5d7
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
The CLI integration test `cli-preview-lifecycle` asserts the thrown error includes the required RBAC permission key. Keep the permission key in the CliUserError message — it is a small bounded enum, so it does not proliferate error-tracking fingerprints — and move only the high-cardinality app id into context. Matches the pattern in cli/src/channel/currentBundle.ts. Generated-By: PostHog Code Task-Id: ab1dbac6-b0af-45ff-980a-8fd68253b5d7
|
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
isExpectedUserErrormatchedmessage.includes(marker), and commitfea2c5739inserted the word "Capgo" into the thrown message — the substring stopped matching, no test failed. A second message (RBAC "Insufficient permissions for app …") was never covered by any marker and interpolated the app id, so it fingerprinted one issue per app.CliUserError, whichshouldCapturePosthogExceptionskips by type. This is the durable pattern already used incli/src/channel/currentBundle.ts. No future reword can break it.cli/src/utils.ts—resolveUserIdFromApiKeythrow new Error('Capgo authentication failed: …')throw new CliUserError('Capgo authentication failed: …')cli/src/api/app.ts—checkAppExistsAndHasPermissionOrgErrthrow new Error(\Insufficient permissions for app ${appid}. … ${requiredPermissionKey}`)`throw new CliUserError('Insufficient permissions for app. …', { appId, requiredPermission })log.errormessages are unchanged — they still print the full detail (including app id and permission key). Only the thrown error type changes.CliUserErrorcontext, so error tracking maps every app to one issue instead of one per app (the same ruleCliUserErrordocuments for dynamic identifiers).cli/src/posthog.tsstays as a fallback for backend-supplied code strings and the 401 status check.Test plan
bun test/test-posthog-exception.mjs— added assertions that both newCliUserErrorthrows are skipped byshouldCapturePosthogException, and that two different app ids produce the same message (one issue, not one per app).bun run lint:oxandbun run typecheckpass.Screenshots
Checklist
bun run lint:backend && bun run lint.accordingly.
my tests
Agent context
7.125.4, an old npx-cached build that predates every fix and will keep sending the original message regardless of what ships. That is handled separately by suppressing pre-8.33.1versions in error tracking — no code change reaches builds already in npx caches.Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.