Skip to content

fix(cli): throw CliUserError for missing package.json - #2971

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-stop-error-tracking-minting-8c2f1b
Draft

fix(cli): throw CliUserError for missing package.json#2971
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-stop-error-tracking-minting-8c2f1b

Conversation

@posthog-eu

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

Copy link
Copy Markdown
Contributor

Summary

Problem

  • Running a CLI command outside a project root mints a fresh error tracking issue, spending team triage time on an expected user error where no user is blocked.
  • Missing package.json was thrown as a plain Error, so shouldCapturePosthogException sent it to error tracking as an unhandled_error.
  • The message interpolated the absolute path, so the fingerprint varied per user and each run could open its own issue.

Changes

  • Throw CliUserError (the marker shouldCapturePosthogException skips) at every missing-package.json site, mirroring the earlier "not logged in" and upload-abort fixes.
  • Keep the thrown message constant and move the path into CliUserError context, so the fingerprint stays stable. log.error still prints the full, path-specific guidance to the user, so nothing changes for the person running the command.
  • Covers three identical sites, not two: readPackageJson, getAllPackagesDependencies, and getDeclaredPackageVersionMap. The report named the first two; the third has the same throw and the same noise, so it is part of the same root cause.
Site Before After
readPackageJson throw new Error(<path-bearing message>) throw new CliUserError(<constant>, { packageJsonPath })
getAllPackagesDependencies throw new Error(<path-bearing message>) throw new CliUserError(<constant>, { packageJsonPath })
getDeclaredPackageVersionMap throw new Error(<path-bearing message>) throw new CliUserError(<constant>, { packageJsonPath })

Test plan

  • bun run test:package-json-guard — updated to assert the thrown error is a CliUserError, the message is constant (no interpolated path), and the path arrives in context.
  • bun run lint — passes.
  • bun run typecheck — passes.

Screenshots

Not applicable. The user-facing message is unchanged; log.error still prints the full path and guidance.

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

Missing package.json was thrown as a plain Error, so shouldCapturePosthogException
sent it to error tracking as an unhandled_error. The message interpolated the
absolute path, so the fingerprint varied per user and each run could open its
own issue.

Throw CliUserError at the three missing-package.json sites (readPackageJson,
getAllPackagesDependencies, getDeclaredPackageVersionMap) so error tracking skips
the expected user error. Keep the thrown message constant and pass the path in
context, so the fingerprint stays stable. log.error still prints the full,
path-specific guidance to the user.

Generated-By: PostHog Code
Task-Id: 602f3bee-b522-4c63-8bee-e669432fb8ae
@codspeed-hq

codspeed-hq Bot commented Aug 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-tracking-minting-8c2f1b (db402e1) with main (bac918f)

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

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