Skip to content

fix(cli): classify auth failures by type, not message text - #2972

Draft
posthog-eu[bot] wants to merge 2 commits into
mainfrom
posthog-self-driving/fixcli-classify-auth-failures-by-type-77efc6
Draft

fix(cli): classify auth failures by type, not message text#2972
posthog-eu[bot] wants to merge 2 commits into
mainfrom
posthog-self-driving/fixcli-classify-auth-failures-by-type-77efc6

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Who is hurt: the team, not users. A message reword two hours after PR fix(cli): stop error-tracking expected user errors and per-version fingerprints #2885 silently broke the substring filter meant to keep CLI auth failures out of error tracking, so expected user-configuration failures are captured as crashes again and bury real CLI crashes.
  • Root cause: classification by free-text message. isExpectedUserError matched message.includes(marker), and commit fea2c5739 inserted 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.
  • Fix — classify by type, not text: convert both throw sites to CliUserError, which shouldCapturePosthogException skips by type. This is the durable pattern already used in cli/src/channel/currentBundle.ts. No future reword can break it.
Throw site Before After
cli/src/utils.tsresolveUserIdFromApiKey throw new Error('Capgo authentication failed: …') throw new CliUserError('Capgo authentication failed: …')
cli/src/api/app.tscheckAppExistsAndHasPermissionOrgErr throw new Error(\Insufficient permissions for app ${appid}. … ${requiredPermissionKey}`)` throw new CliUserError('Insufficient permissions for app. …', { appId, requiredPermission })
  • The user-facing log.error messages are unchanged — they still print the full detail (including app id and permission key). Only the thrown error type changes.
  • 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 (the same rule CliUserError documents for dynamic identifiers).
  • The marker list in cli/src/posthog.ts stays 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 new CliUserError throws are skipped by shouldCapturePosthogException, and that two different app ids produce the same message (one issue, not one per app).
  • bun run lint:ox and bun run typecheck pass.

Screenshots

Checklist

  • My code follows the code style of this project and passes
    bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation
    accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce
    my tests

Agent context


Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

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
@codspeed-hq

codspeed-hq Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing posthog-self-driving/fixcli-classify-auth-failures-by-type-77efc6 (d3735c6) with main (bac918f)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants