fix: infer template from --marketplace-code to prevent silent deploy failure#207
Conversation
…failure (zeabur#202) When running `service deploy --marketplace-code postgresql` without `--template`, the command would silently fail without creating a service or showing a useful error. This adds automatic template inference from the provided flags (--marketplace-code implies PREBUILT, --repo-id implies GIT) and improves error messages with usage examples. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/cmd/service/deploy/deploy.go`:
- Around line 263-266: The current check only ensures opts.marketplaceCode is
present for template == "PREBUILT" but does not validate that the value is one
of the available marketplace codes; update the validation in the same branch
(where template and opts.marketplaceCode are checked) to call the marketplace
listing API/client to fetch the set of valid codes (e.g., use the existing
marketplace/catalog client method in this package), compare opts.marketplaceCode
against that set, and if it is not found return a user-friendly error that
includes the list of valid codes and the example usage (instead of deferring to
backend errors). Ensure the lookup is case/whitespace-normalized and perform
this validation early in the deploy flow before attempting to create or send the
request.
- Around line 64-67: The current inference sets opts.template = "GIT" when
opts.repoID != 0 but the interactive GIT prompt can still run and overwrite
opts.repoID/template; update the deploy flow to treat presence of --repo-id as
authoritative by (a) setting opts.template and a flag like opts.skipInteractive
or opts.interactive=false when opts.repoID != 0 (or moving the repo-id check
before any interactive logic), and (b) guarding the interactive repository
selection routine to return early if opts.repoID != 0 (or opts.skipInteractive
is true) so the prompt cannot overwrite opts.repoID or opts.template; locate and
modify the code around opts.template, opts.repoID, and the interactive GIT
prompt function in deploy.go to implement this change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: df83edad-bfb7-4185-abff-a88789fc3da1
📒 Files selected for processing (1)
internal/cmd/service/deploy/deploy.go
| if opts.marketplaceCode != "" { | ||
| opts.template = "PREBUILT" | ||
| } else if opts.repoID != 0 { | ||
| opts.template = "GIT" |
There was a problem hiding this comment.
--repo-id inference still conflicts with interactive flag precedence.
When this infers GIT from --repo-id, the interactive GIT flow still prompts repository selection and can overwrite the provided repo. That makes the flag non-authoritative in interactive mode.
As per coding guidelines: "Commands should support both interactive and non-interactive modes; if a flag is provided, skip the interactive prompt."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/cmd/service/deploy/deploy.go` around lines 64 - 67, The current
inference sets opts.template = "GIT" when opts.repoID != 0 but the interactive
GIT prompt can still run and overwrite opts.repoID/template; update the deploy
flow to treat presence of --repo-id as authoritative by (a) setting
opts.template and a flag like opts.skipInteractive or opts.interactive=false
when opts.repoID != 0 (or moving the repo-id check before any interactive
logic), and (b) guarding the interactive repository selection routine to return
early if opts.repoID != 0 (or opts.skipInteractive is true) so the prompt cannot
overwrite opts.repoID or opts.template; locate and modify the code around
opts.template, opts.repoID, and the interactive GIT prompt function in deploy.go
to implement this change.
| if template == "PREBUILT" && opts.marketplaceCode == "" { | ||
| return fmt.Errorf("--marketplace-code is required for PREBUILT template\n" + | ||
| " Example: zeabur service deploy --template PREBUILT --marketplace-code postgresql --project-id <id>") | ||
| } |
There was a problem hiding this comment.
Unknown --marketplace-code is still not pre-validated with available-code hints.
This only checks presence, not validity. For invalid codes, users still depend on backend failure paths instead of getting the expected list of valid marketplace codes in CLI output.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/cmd/service/deploy/deploy.go` around lines 263 - 266, The current
check only ensures opts.marketplaceCode is present for template == "PREBUILT"
but does not validate that the value is one of the available marketplace codes;
update the validation in the same branch (where template and
opts.marketplaceCode are checked) to call the marketplace listing API/client to
fetch the set of valid codes (e.g., use the existing marketplace/catalog client
method in this package), compare opts.marketplaceCode against that set, and if
it is not found return a user-friendly error that includes the list of valid
codes and the example usage (instead of deferring to backend errors). Ensure the
lookup is case/whitespace-normalized and perform this validation early in the
deploy flow before attempting to create or send the request.
Summary
template = "PREBUILT"when--marketplace-codeis providedtemplate = "GIT"when--repo-idis providedparamCheckwith concrete usage examplesProblem
service deploy --marketplace-code postgresqlsilently fails without creating a service because--templateis not set, and in non-interactive mode the validation error is vague.Changes
internal/cmd/service/deploy/deploy.go— addedinferTemplate()function called before the interactive/non-interactive split, improved error messagesBefore/After
Fixes #202
Summary by CodeRabbit
New Features
Bug Fixes