fix(cli): recover bundle zip setup failures before aborting

Merged
PO
2mo ago
+260-12

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)MessageJSON code
Semver checkInvalid bundle version formatinvalid_semver
Missing argumentMissing appId/bundle/pathmissing_argument
notifyAppReadynotifyAppReady() is missing in build foldernotifyAppReady_not_in_source_code
index.htmlindex.html is missing in root folderindex_html_not_found
updater pluginCannot 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.

Summary by CodeRabbit

  • New Features

    • Added interactive recovery for invalid or missing bundle versions.
    • Added prompts to locate missing web directories.
    • Added automatic installation or restoration of missing updater components.
    • Added local fallback version handling when bundle metadata is unavailable.
    • Added retries for updater discovery after recovery actions.
  • Bug Fixes

    • Improved bundle creation reliability when app-readiness notifications fail.
    • Added clearer error reporting and input validation during recovery.
    • Improved installation checks to confirm updater recovery succeeded.