Skip to content

fix: infer template from --marketplace-code to prevent silent deploy failure#207

Open
Raymondhou0917 wants to merge 1 commit intozeabur:mainfrom
Raymondhou0917:fix/marketplace-deploy-error-handling
Open

fix: infer template from --marketplace-code to prevent silent deploy failure#207
Raymondhou0917 wants to merge 1 commit intozeabur:mainfrom
Raymondhou0917:fix/marketplace-deploy-error-handling

Conversation

@Raymondhou0917
Copy link
Copy Markdown

@Raymondhou0917 Raymondhou0917 commented Mar 27, 2026

Summary

  • Auto-infer template = "PREBUILT" when --marketplace-code is provided
  • Auto-infer template = "GIT" when --repo-id is provided
  • Improve error messages in paramCheck with concrete usage examples

Problem

service deploy --marketplace-code postgresql silently fails without creating a service because --template is not set, and in non-interactive mode the validation error is vague.

Changes

  • internal/cmd/service/deploy/deploy.go — added inferTemplate() function called before the interactive/non-interactive split, improved error messages

Before/After

# Before: silently fails
zeabur service deploy --marketplace-code postgresql --project-id <id> -i=false

# After: automatically infers --template PREBUILT and proceeds
zeabur service deploy --marketplace-code postgresql --project-id <id> -i=false

Fixes #202

Summary by CodeRabbit

  • New Features

    • Deploy command now automatically infers the deployment template based on provided flags: marketplace-code for prebuilt deployments, repo-id for Git-based deployments.
  • Bug Fixes

    • Improved parameter validation with detailed error messages that specify required flags for each deployment type and include usage examples.

…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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Walkthrough

The service deploy command now automatically infers the deployment template type based on provided flags before validating parameters. If --marketplace-code is set, the template defaults to PREBUILT; if --repo-id is set, it defaults to GIT. Parameter validation was enhanced to provide specific error messages and examples for missing required flags per template type.

Changes

Cohort / File(s) Summary
Template Inference & Parameter Validation
internal/cmd/service/deploy/deploy.go
Added inferTemplate function to automatically derive template type from flags (--marketplace-code → PREBUILT, --repo-id → GIT), and enhanced paramCheck validation to provide template-specific error messages with required flag examples and acceptable template values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: inferring template from --marketplace-code flag to prevent silent deploy failures.
Linked Issues check ✅ Passed The PR implements the core requirements from issue #202: auto-inferring template from --marketplace-code and improving validation error messages with concrete examples.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objectives: inferring template, improving paramCheck validation, and fixing the silent deploy failure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 76b8768 and 66a1867.

📒 Files selected for processing (1)
  • internal/cmd/service/deploy/deploy.go

Comment on lines +64 to +67
if opts.marketplaceCode != "" {
opts.template = "PREBUILT"
} else if opts.repoID != 0 {
opts.template = "GIT"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

--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.

Comment on lines +263 to 266
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>")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

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.

service deploy --marketplace-code silently fails without creating a service

1 participant