Skip to content

fix(cli): CliUserError for app add when app ID is taken - #3300

Open
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-stop-error-reporting-the-taken-b63df6
Open

fix(cli): CliUserError for app add when app ID is taken#3300
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-stop-error-reporting-the-taken-b63df6

Conversation

@posthog-eu

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

Copy link
Copy Markdown
Contributor

Summary

  • Problem: app add still files false error-tracking issues on the newest release. When an app ID is registered to another organization — a normal user situation — the CLI prints a clear message and exits non-zero, but the throw was a plain Error, so shouldCapturePosthogException captured it as an unhandled crash.
  • Mechanism: The three Could not add app … exits in addAppInternal now throw CliUserError. shouldCapturePosthogException skips CliUserError by type, so these expected states no longer open a $exception issue. Non-zero exit, printed message, and failure analytics are unchanged.
  • This is the same fix already shipped for bundle upload (Version X already exists), applied to the last branch in the %already exists% family still filing issues.
Exit path (cli/src/app/add.ts) Before After
Ownership verification failed throw new Error throw new CliUserError
App ID taken by another org (the reported symptom) throw new Error throw new CliUserError
Other create failure throw new Error throw new CliUserError

Test plan

  • bun run test:posthog-exception — extended to assert the app add taken-ID message is filtered by type.
  • bun run test:app-add-exists
  • bun run lint
  • bun run typecheck

Screenshots

Checklist

  • My code follows the code style of this project and passes 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

  • The report also suggested folding in two extras. I verified both and dropped them: checkAlerts in cli/src/api/update.ts has ~15 callers (including add.ts:297), so the "no caller" claim is stale; and the shared-fingerprint concern is inherent to the error-tracking design and out of scope for this symptom.

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

The three "Could not add app" exits in addAppInternal threw a plain Error, so
error tracking captured them as unhandled crashes. An app ID taken by another
organization is a normal user state — the CLI prints a clear message and exits
non-zero. Throw CliUserError instead so shouldCapturePosthogException filters it
by type, matching how bundle upload handles "Version X already exists".

Generated-By: PostHog Desktop
Task-Id: 04404da2-540e-439a-8087-b57153a51d63
@codspeed-hq

codspeed-hq Bot commented Sep 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-stop-error-reporting-the-taken-b63df6 (dfe6b4f) with main (387a845)

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.

@sonarqubecloud

Copy link
Copy Markdown

@posthog-eu
posthog-eu Bot marked this pull request as ready for review September 10, 2026 13:04
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 198bd3ff-0b5b-4bb8-848d-ccf8ac45200d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor

cursor Bot commented Sep 10, 2026

Copy link
Copy Markdown

Coding is complete on HEAD dfe6b4f. CI is green; CodeRabbit skipped review (bot-authored PR). Ready for human/AI review when convenient.

@cursor

cursor Bot commented Sep 10, 2026

Copy link
Copy Markdown

AI review: APPROVED

Reviewed dfe6b4f on posthog-self-driving/fixcli-stop-error-reporting-the-taken-b63df6.

Diff check

  • addAppInternal now throws CliUserError (not Error) on the three app-add failure paths: ownership-resolution error, taken app ID (duplicate_taken), and other duplicate outcomes.
  • CliUserError is already imported in cli/src/app/add.ts (line 12); no new import needed.
  • shouldCapturePosthogException in cli/src/posthog.ts returns false for error instanceof CliUserError unless the message is in TRACKED_CLI_USER_ERROR_MESSAGES (only iOS sync validation). These app-add messages are not tracked.
  • Test assert in cli/test/test-posthog-exception.mjs documents the contract for the taken-app-ID case.

Rationale: Expected user outcomes (app ID already taken / ownership conflict) should not open PostHog error-tracking issues. This matches existing CLI patterns (uploadFail, login cancel, duplicate version upload, etc.). CI green; no code issues found.

Note: Could not submit a formal GitHub APPROVE review from this agent token (Resource not accessible by integration on addPullRequestReview). Merge still needs a human/org reviewer with approval rights to clear REVIEW_REQUIRED.

@TorichanCapgo TorichanCapgo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — 3× Error→CliUserError in addAppInternal + test; matches existing PostHog skip-by-type pattern. AI review clear; CR skips bot author.

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.

1 participant