-
Notifications
You must be signed in to change notification settings - Fork 13
fix: correct region index mapping in template deploy when unavailable regions are filtered #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… regions are filtered When free tier users deploy using CLI template deploy command and select a region, they were encountering "REQUIRE_PAID_PLAN" errors even when selecting available regions. This was caused by an index mismatch bug in pkg/selector/selector.go where: - regionOptions array contained only available regions (filtered) - User selected an index from this filtered list - Code used that index on the original unfiltered regions array This resulted in selecting the wrong region (potentially an unavailable one). The fix creates a separate availableRegions array and uses it for indexing, matching the pattern already applied to internal/cmd/project/create/create.go in commit 8e5d1ab.
WalkthroughModifies region selection logic in the selector package to filter regions by availability before using them for project creation, ensuring the selected region index corresponds to an available region. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical bug where free tier users selecting a region during CLI template deployment would encounter "REQUIRE_PAID_PLAN" errors even when choosing available regions. The issue was caused by an index mismatch between filtered and unfiltered region arrays.
Changes:
- Added
availableRegionsslice to track only available regions alongside the existingregionOptionsstring array - Updated region selection logic to use
availableRegionsarray instead of the original unfilteredregionsarray when mapping user's selected index
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/selector/selector.go (1)
105-119: Guard against zero available regions before prompting/indexing.If all regions are unavailable,
availableRegionsis empty and the subsequent indexing can panic. Handle the empty case explicitly and return a user-facing error.🐛 Proposed fix
availableRegions := make([]model.GenericRegion, 0, len(regions)) regionOptions := make([]string, 0, len(regions)) for _, region := range regions { if region.IsAvailable() { availableRegions = append(availableRegions, region) regionOptions = append(regionOptions, region.String()) } } + if len(availableRegions) == 0 { + return nil, nil, errors.New("no available regions for your plan") + } projectRegionIndex, err := s.prompter.Select("Select project region", "", regionOptions) if err != nil { return nil, nil, fmt.Errorf("select project region failed: %w", err) } projectRegion := availableRegions[projectRegionIndex].GetID()
Before:

After:

When free tier users deploy using CLI template deploy command and select a region,
they were encountering "REQUIRE_PAID_PLAN" errors even when selecting available regions.
This was caused by an index mismatch bug in pkg/selector/selector.go where:
This resulted in selecting the wrong region (potentially an unavailable one).
The fix creates a separate availableRegions array and uses it for indexing,
matching the pattern already applied to internal/cmd/project/create/create.go
in commit 8e5d1ab.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.