feat(init): add --team flag to relay team selection to project creation#403
feat(init): add --team flag to relay team selection to project creation#403MathurAditya724 merged 2 commits intomainfrom
Conversation
When users belong to multiple teams, the create-project step during init would fail with a ContextError asking them to specify --team. The init command had no way to accept that flag. This adds --team/-t to sentry init, threading it through WizardOptions to resolveOrCreateTeam so team resolution is skipped when explicitly set.
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Init
Issue List
Other
Bug Fixes 🐛Init
Other
Internal Changes 🔧Init
Other
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 104 passed | Total: 104 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 917 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 95.50% 95.49% -0.01%
==========================================
Files 142 142 —
Lines 20343 20352 +9
Branches 0 0 —
==========================================
+ Hits 19427 19435 +8
- Misses 916 917 +1
- Partials 0 0 —Generated by Codecov Action |
| yes: flags.yes, | ||
| dryRun: flags["dry-run"], | ||
| features: featuresList, | ||
| team: flags.team, | ||
| }); | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Bug: The sentry init command with the --team flag lacks validation for non-existent team slugs, resulting in a generic API error instead of a helpful message.
Severity: MEDIUM
Suggested Fix
Implement the same sophisticated error handling found in the project create command within the init command's workflow. Specifically, when a 404 error is received from the createProject API call, check if the cause was an invalid team slug and, if so, provide a user-friendly error message that lists the available teams for the organization.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/commands/init.ts#L81-L87
Potential issue: When the `sentry init` command is used with the new `--team` flag, the
provided team slug is not validated. If a user supplies a slug for a team that does not
exist, the CLI will proceed to call the project creation API endpoint. This API call
will fail with a 404 error, but the error handling in the `init` command is generic.
Unlike the `sentry project create` command, which has specific logic to detect a
non-existent team and provide a helpful message listing available teams, the `init`
command will only show the user a raw, unhelpful API error message.
Did we get this right? 👍 / 👎 to inform future reviews.
Summary
--team/-tflag tosentry initso users on multiple teams can specify which team to create the project underWizardOptions→handleLocalOp→createSentryProject→resolveOrCreateTeamsentry initfails with aContextErrorwhen users belong to multiple teams, since there was no way to pass the--teamflag thatproject createalready supportsUsage