Skip to content

fix(cli): don't crash on empty bundle list or hoisted monorepo deps - #2884

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-stop-throwing-on-empty-bundle-cd0241
Draft

fix(cli): don't crash on empty bundle list or hoisted monorepo deps#2884
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-stop-throwing-on-empty-bundle-cd0241

Conversation

@posthog-eu

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

Copy link
Copy Markdown

Summary

Two normal situations make the CLI exit non-zero instead of behaving sensibly. This fixes both, plus a fingerprint quirk that hides their true reach.

  • Empty bundle list crashes. bundle list on an app with zero bundles printed Active versions in Capgo: 0 and then threw No bundle found on that same empty array — skipping outro('Done ✅') and exiting 1. Nastiest in CI, where exit 1 fails the job. displayBundles now renders an empty state and returns; bundle cleanup (same call site) is fixed for free.
  • Hoisted monorepo deps read as missing. Dependency enumeration (getAllPackagesDependencies) walks up parent directories for hoisted node_modules, but the validation in getLocalDependencies only checked a flat [cwd()/node_modules]. Anything hoisted to a workspace root therefore failed with Missing dependencies or invalid dependencies, blocking bundle upload / doctor. Validation now uses the same parent-directory walk, so enumeration and validation agree.
  • Every release minted a new error-tracking issue. The exception fingerprint baked in cli:${version}, so the identical bug became a brand-new "1 user" issue on each release. The CLI version is now excluded from the fingerprint (still sent as distinct_id / cli_version).

Also drops a .catch(() => []) in getLocalDependencies that swallowed genuine node_modules read errors into an empty array.

Test plan

  • bun test/test-posthog-exception.mjs — asserts the fingerprint no longer contains the CLI version.
  • bun test/test-native-dependencies.mjs — adds a monorepo-hoisting scenario (dep at the workspace-root node_modules, resolved from the app dir with no --node-modules).
  • bun run typecheck and bun run lint pass.

Screenshots

N/A — CLI exit-code / error-handling change.

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

- displayBundles now renders an empty state and returns instead of throwing
  "No bundle found", so `bundle list` on an app with zero bundles exits 0.
- getLocalDependencies validates dependencies by walking up parent
  node_modules directories (matching getAllPackagesDependencies), so deps
  hoisted to a workspace/monorepo root are no longer reported as missing.
- Drop the `.catch(() => [])` that swallowed genuine read errors into an
  empty array.
- Exclude the CLI version from the exception fingerprint so the same bug
  stays one error-tracking issue across releases.

Generated-By: PostHog Code
Task-Id: 53a6eb16-3315-4a2b-bfcf-c0d3c122346b
@codspeed-hq

codspeed-hq Bot commented Aug 6, 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-throwing-on-empty-bundle-cd0241 (8a81fa9) with main (60a641e)

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 6, 2026

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