Skip to content

fix(init): recover from member project-creation restriction#960

Merged
betegon merged 3 commits into
mainfrom
fix/init-project-creation-member-permission
May 12, 2026
Merged

fix(init): recover from member project-creation restriction#960
betegon merged 3 commits into
mainfrom
fix/init-project-creation-member-permission

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented May 12, 2026

When the wizard tries to create a Sentry project, it fails with a 403 if the org has `disable_member_project_creation` set — which is the default for every new org (`organization.py:256`). The error message then appended "Re-authenticate with: `sentry auth login`", which is completely wrong advice for an org policy issue.

Tracked in CLI-SERVER-E (21 events, 11 users including internal).

What changes

Clear error with an escape hatch (`create-sentry-project.ts`) — when the org rejects project creation for members, surface the actual problem and tell the user what to do:

```
Project creation is disabled for members in "acme".
Ask an org owner to either enable project creation for members
or create the project for you. Once the project exists, run:
sentry init acme/
```

The `sentry init /` escape hatch is real — preflight resolves the positional arg to an existing project and `createSentryProject` short-circuits before touching the create API.

A previous iteration retried with a `team:admin` team, but that was wrong: the user chose that org and we shouldn't alter its structure silently. It also only paginated the first page of teams, missing admin memberships on large orgs. The right answer is a clear error, not a silent workaround.

Fix misleading 403 enrichment (`infrastructure.ts`) — `enrich403Detail` now short-circuits on `"disabled this feature"` before the scope/re-auth branches, so the wrong advice never reaches the user from any command.

Type the org fields (`sentry.ts`) — adds `allowMemberProjectCreation?` and `orgRole?` to `SentryOrganization` for future use.

Testing

  • 1 new test in `create-sentry-project.test.ts`: clear error with `sentry init` guidance, no re-auth text
  • 2 new tests in `infrastructure.test.ts`: no re-auth advice for org-policy 403s, no token-scope advice for org-policy 403s
  • All 23 tests pass; baseline failure count unchanged

Fixes CLI-SERVER-E.

New Sentry orgs have `disable_member_project_creation = true` by default.
When `sentry init` hit this 403, it bailed with "Re-authenticate with:
sentry auth login" — which is wrong advice and confuses users (CLI-SERVER-E,
21 events).

Three changes:

1. `create-sentry-project.ts` — after a 403 "disabled this feature" on the
   auto-resolved team, check whether the user holds `team:admin` on any team
   (that role bypasses the org restriction per `team_projects.py:228–233`).
   If found, retry with that team transparently. If not, surface a clear
   actionable error instead of the misleading re-auth prompt. Explicit
   `--team` skips the retry so the user's intent isn't overridden.

2. `infrastructure.ts` — `enrich403Detail` now short-circuits on
   "disabled this feature" before the scope/re-auth enrichment, so the
   wrong advice never reaches the user from any command.

3. `sentry.ts` — types `allowMemberProjectCreation` and `orgRole` on
   `SentryOrganization` for future preemptive checks.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-960/

Built to branch gh-pages at 2026-05-12 20:09 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

Codecov Results 📊

6945 passed | Total: 6945 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +6
Passed Tests 📈 +6
Failed Tests
Skipped Tests

All tests are passing successfully.

❌ Patch coverage is 75.00%. Project has 14136 uncovered lines.
✅ Project coverage is 77%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/lib/init/tools/create-sentry-project.ts 65.00% ⚠️ 7 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    76.97%    77.00%    +0.03%
==========================================
  Files          320       320         —
  Lines        61442     61458       +16
  Branches         0         0         —
==========================================
+ Hits         47294     47322       +28
- Misses       14148     14136       -12
- Partials         0         0         —

Generated by Codecov Action

@betegon betegon marked this pull request as ready for review May 12, 2026 15:21
Comment thread src/lib/init/tools/create-sentry-project.ts Outdated
betegon and others added 2 commits May 12, 2026 21:41
The team-swap retry was wrong: silently creating a project under a
different team changes org structure the user didn't ask for. Bot
review also correctly flagged that listTeams only returns one page,
so the retry would miss admin teams on large orgs — but the right fix
is to remove it, not fix the pagination.

When the org has member project creation disabled, tell the user:
1. What happened (org policy, not an auth issue)
2. How to unblock: ask an admin to enable the setting OR create the
   project for them — then `sentry init <org>/<slug>` resolves to
   the existing project via preflight and skips creation entirely.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Add four targeted tests to cover previously uncovered branches:
- Invalid slug: name that slugifies to empty string returns early
- 403 org-policy: clear error with sentry-init escape hatch, no re-auth text
- Tool describe with payload.detail: short-circuits to the provided string
- Tool describe fallback: uses project name and platform

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@betegon betegon force-pushed the fix/init-project-creation-member-permission branch from 16937d0 to 57ad6f6 Compare May 12, 2026 20:08
@betegon betegon merged commit 49f151f into main May 12, 2026
29 checks passed
@betegon betegon deleted the fix/init-project-creation-member-permission branch May 12, 2026 20:55
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.

1 participant