fix(cli): throw CliUserError for capacitor config and org lookup

Merged
RI
2mo ago
+193-25

Summary (AI generated)

  • getConfigFrom throws CliUserError with constant message No capacitor config file found, run \cap init` first; underlying diagnostics (including TypeScript load failures) go to log.errorandcontext.cause` instead of the thrown message.
  • resolveCapacitorConfigTargetPath throws CliUserError with constant messages for empty / missing / invalid filename / outside-cwd cases; resolved paths live in context.path.
  • getOrganizationId throws CliUserError('Cannot get organization id for app') with { appId, cause } in context; enriched log.error unchanged.
  • Added test-cli-user-error-config.mjs and updated capacitor-config-target / PostHog exception tests.

Motivation (AI generated)

PostHog project 22029 still groups expected CLI user mistakes as high-volume exceptions because plain Error messages embed dynamic paths, app IDs, and wrapped formatError text — creating unstable fingerprints and noise in error tracking.

Related issues:

  • No capacitor config and related “No capacitor config file found, run cap init first …” variants (including TypeScript-missing wrapped messages from getConfigFrom catch path).
  • Capacitor config path user mistakes: Capacitor config path does not exist: <path> (and empty/invalid/outside-cwd variants) from resolveCapacitorConfigTargetPath.
  • Cannot get organization id when app is missing or API key cannot read the app.

Business Impact (AI generated)

Reduces false-positive CLI exception volume in PostHog so engineering can focus on real crashes. Expected user configuration and lookup failures remain visible via trackCommandFailed / failure analytics without opening separate error-tracking issues per path or app ID.

Test Plan (AI generated)

  • bun run build (cli)
  • bun run test:cli-user-error-config
  • bun run test:posthog-exception
  • bun run test:capacitor-config-target
  • bun run lint (cli)

Generated with AI

Open in Web Open in Cursor 

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

  • Bug Fixes

    • Improved CLI error messages for invalid, missing, empty, or inaccessible Capacitor configuration files.
    • Added clearer path context for unsupported extensions, invalid locations, symlink escapes, and directory targets.
    • Improved organization lookup failure reporting with actionable application context.
    • Prevented expected user configuration errors from being misclassified as unexpected exceptions.
  • Tests

    • Expanded coverage for configuration validation and organization lookup failures.