Skip to content

fix(domain): add --domain validation and fix spinner leaks in domain create#222

Open
stantheman0128 wants to merge 1 commit intozeabur:mainfrom
stantheman0128:fix/domain-create-non-interactive-validation
Open

fix(domain): add --domain validation and fix spinner leaks in domain create#222
stantheman0128 wants to merge 1 commit intozeabur:mainfrom
stantheman0128:fix/domain-create-non-interactive-validation

Conversation

@stantheman0128
Copy link
Copy Markdown

@stantheman0128 stantheman0128 commented Apr 10, 2026

Summary

  • Add missing --domain flag validation in non-interactive mode — previously, omitting --domain would pass an empty string to the API, producing a confusing server error
  • Fix spinner goroutine leaks in 3 error paths where s.Stop() was not called before returning

Changes

Location Fix
runCreateDomainNonInteractive Add --domain empty check with clear error message
runCreateDomainNonInteractive line 192 Call s.Stop() before returning on AddDomain error
runCreateDomainInteractive line 111 Call s.Stop() before returning on CheckDomainAvailable error
runCreateDomainInteractive line 128 Call s.Stop() before returning on ListDomains error

Reproducing the bug

# Missing --domain: previously sent empty string to API
zeabur domain create --id <service-id> -g -i=false
# Before: confusing API error
# After: "Error: --domain is required in non-interactive mode"

Test plan

  • Verify domain create --id <id> -i=false without --domain returns clear error
  • Verify domain create --id <id> --domain test -g -i=false still works
  • Verify spinner does not leak on API errors (no lingering animation in terminal)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling in domain creation to prevent application hangs and ensure proper cleanup when errors occur
    • Added validation requiring the domain name parameter in non-interactive mode
    • Improved failure handling during domain operations to maintain system stability and prevent incomplete transactions

…create

In non-interactive mode, `domain create` proceeds with an empty domain
name if --domain is not provided, causing a confusing API error. Add
validation to require the --domain flag.

Also fix spinner goroutine leaks where s.Stop() is not called before
returning on error in both interactive and non-interactive paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Walkthrough

The changes add explicit spinner cleanup on error paths in domain creation functions and introduce validation to ensure the domain name is provided when running in non-interactive mode.

Changes

Cohort / File(s) Summary
Error Handling & Input Validation
internal/cmd/domain/create/create.go
Added s.Stop() calls on error paths in runCreateDomainInteractive and runCreateDomainNonInteractive to ensure spinner cleanup before returning errors. Added validation in non-interactive mode to require --domain flag, returning an error if missing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding domain validation and fixing spinner leaks in the domain create command.

✏️ 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: 1

🤖 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/domain/create/create.go`:
- Around line 167-169: The current non-interactive validation only checks
opts.domainName == "" and allows whitespace-only names; change the check to trim
whitespace (e.g., use strings.TrimSpace on opts.domainName) and treat a trimmed
empty string the same as missing, returning the existing error
fmt.Errorf("--domain is required in non-interactive mode"); update the
validation in the same function where opts.domainName is currently checked so
whitespace-only inputs are rejected early.
🪄 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: a1eeadaf-a745-4546-b8e1-d7173cb19c6a

📥 Commits

Reviewing files that changed from the base of the PR and between 4750f37 and b209bd1.

📒 Files selected for processing (1)
  • internal/cmd/domain/create/create.go

Comment on lines +167 to +169
if opts.domainName == "" {
return fmt.Errorf("--domain is required in non-interactive mode")
}
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 | 🟡 Minor

Harden --domain validation against whitespace-only input.

Line 167 currently rejects only "". Values like " " still pass and can fail later with a confusing API error.

🔧 Suggested patch
 import (
 	"context"
 	"fmt"
+	"strings"
@@
-	if opts.domainName == "" {
+	if strings.TrimSpace(opts.domainName) == "" {
 		return fmt.Errorf("--domain is required in non-interactive mode")
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if opts.domainName == "" {
return fmt.Errorf("--domain is required in non-interactive mode")
}
import (
"context"
"fmt"
"strings"
)
// ... existing code ...
if strings.TrimSpace(opts.domainName) == "" {
return fmt.Errorf("--domain is required in non-interactive mode")
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/cmd/domain/create/create.go` around lines 167 - 169, The current
non-interactive validation only checks opts.domainName == "" and allows
whitespace-only names; change the check to trim whitespace (e.g., use
strings.TrimSpace on opts.domainName) and treat a trimmed empty string the same
as missing, returning the existing error fmt.Errorf("--domain is required in
non-interactive mode"); update the validation in the same function where
opts.domainName is currently checked so whitespace-only inputs are rejected
early.

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