fix(cli): check app exists before uploading bundle - #2903
Draft
posthog-eu[bot] wants to merge 1 commit into
Draft
Conversation
Verify app existence and app.upload_bundle permission before sending any bundle bytes, so an unregistered app fails fast with the actionable `app add` hint instead of uploading the whole bundle and then hitting a raw tus `app_not_found` 404. Also map `app_not_found` in both tus onError handlers (full and partial upload) onto the same hint, thrown as an expected user error rather than leaking a raw tus error object as an unhandled rejection. Generated-By: PostHog Code Task-Id: 21353ace-1cf6-473e-8eab-7be05b6d2442
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
bundle uploadto an app that was never registered uploaded the whole bundle before failing, then surfaced a raw tusapp_not_found404 (and, on the delta path, an unhandled rejection) instead of the CLI's ownapp addguidance — a confusing dead end on the exact activation moment a new user decides whether Capgo works.checkAppExistsAndHasPermissionOrgErr) ran after the TUS uploads. For an unknown app the files backend rejects the upload with404 app_not_found(supabase/functions/_backend/files/files.ts), and the partial path re-threw the raw tus error object, escaping as an unhandled rejection.run first `npx @capgo/cli app add <id>`). As defense-in-depth, both tusonErrorhandlers now mapapp_not_foundonto the same hint, thrown as an expected user error.app_not_found404app addhintapp addhintNote:
getOrganizationIdalready ran before the uploads and would throw a genericCannot get organization id for app id <id>for a truly nonexistent app — so the earlier check also replaces that unclear message with the actionable one. The tus-handler mapping covers the remaining races (e.g. app deleted mid-flight) where the backend still returnsapp_not_found.Same pattern as #2896 and #2885. No open PR touches these paths.
Test plan
bun run typecheck,bun run lint:ox(both pass), andbun run test:upload(passes).bundle upload <unregistered-app-id>and confirm it errors immediately with theapp addhint and sends no bundle bytes.Screenshots
N/A — CLI error-message change only.
Checklist
bun run lint:backend && bun run lint.accordingly.
my tests
Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.