Skip to content

fix(cli): throw CliUserError from bundle zip expected failures - #2954

Open
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-throw-cliusererror-from-bundle-b1ae1e
Open

fix(cli): throw CliUserError from bundle zip expected failures#2954
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-throw-cliusererror-from-bundle-b1ae1e

Conversation

@posthog-eu

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

Copy link
Copy Markdown
Contributor

Summary

  • Who is hurt: genuine CLI crashes get buried. bundle zip's five expected user-configuration aborts still open error tracking $exception issues, sharded across many fingerprints, which keep resurfacing as brand-new issues.
  • Root cause: cli/src/bundle/zip.ts threw bare Error in five places, so shouldCapturePosthogException never skipped them — unlike bundle upload, which routes every abort through uploadFail and throws CliUserError.
  • Fix: swap the five bare throw new Error(...) calls for CliUserError (from cli/src/shared/cli-user-error.ts). shouldCapturePosthogException already skips that type.

The user experience was already correct — each site prints a clear message and a machine-readable emitJsonError code before it throws. Only the telemetry was wrong.

Site (zip.ts) Message JSON code
Semver check Invalid bundle version format invalid_semver
Missing argument Missing appId/bundle/path missing_argument
notifyAppReady notifyAppReady() is missing in build folder notifyAppReady_not_in_source_code
index.html index.html is missing in root folder index_html_not_found
updater plugin Cannot find @capgo/capacitor-updater in node_modules (warn)

Notes:

  • No zipFail helper was added. Each site already gates its logging inline on silent/json, so a helper would not co-locate log + throw the way uploadFail does — it would only add indirection.
  • The catch block (error instanceof Error ? error : new Error(String(error))) passes CliUserError straight through, since it extends Error. Exit codes and analytics events are unchanged; only the $exception capture goes away.

Test plan

  • bundle zip on a build folder missing notifyAppReady() still prints the same error and exits non-zero, but no error tracking $exception issue is opened.
  • Verify each of the five aborts (bad semver, missing argument, missing notifyAppReady, missing index.html, missing updater plugin) behaves as before, in both default and --json output.

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

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 five expected user-configuration aborts in `cli/src/bundle/zip.ts`
threw bare `Error`, so `shouldCapturePosthogException` still opened an
error tracking `$exception` issue for each. Swap them to `CliUserError`,
the same marker `bundle upload` already uses through `uploadFail`, so the
telemetry skips these deliberate stops. Messages, exit codes, and the
existing analytics events stay unchanged.

Generated-By: PostHog Code
Task-Id: 07a4bba7-a89a-4f63-a64b-e1253273dd2d
@codspeed-hq

codspeed-hq Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing posthog-self-driving/fixcli-throw-cliusererror-from-bundle-b1ae1e (8429399) with main (b62668a)

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

sonarqubecloud Bot commented Aug 8, 2026

Copy link
Copy Markdown

@riderx
riderx marked this pull request as ready for review August 8, 2026 22:18
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