From b209bd1104b1d661908dbdc21c59175844ce77d2 Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Fri, 10 Apr 2026 23:38:23 +0800 Subject: [PATCH] fix(domain): add --domain validation and fix spinner leaks in domain 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 --- internal/cmd/domain/create/create.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/cmd/domain/create/create.go b/internal/cmd/domain/create/create.go index 681277f..4cab493 100644 --- a/internal/cmd/domain/create/create.go +++ b/internal/cmd/domain/create/create.go @@ -109,6 +109,7 @@ func runCreateDomainInteractive(f *cmdutil.Factory, opts *Options) error { s.Start() available, _, err := f.ApiClient.CheckDomainAvailable(context.Background(), opts.domainName, opts.IsGenerated, project.Region.ID) if err != nil { + s.Stop() return err } s.Stop() @@ -125,6 +126,7 @@ func runCreateDomainInteractive(f *cmdutil.Factory, opts *Options) error { s.Start() existedDomains, err := f.ApiClient.ListDomains(context.Background(), opts.id, opts.environmentID) if err != nil { + s.Stop() return err } s.Stop() @@ -162,6 +164,10 @@ func runCreateDomainNonInteractive(f *cmdutil.Factory, opts *Options) error { return fmt.Errorf("--id or --name is required") } + if opts.domainName == "" { + return fmt.Errorf("--domain is required in non-interactive mode") + } + if opts.environmentID == "" { envID, err := util.ResolveEnvironmentIDByServiceID(f.ApiClient, opts.id) if err != nil { @@ -184,6 +190,7 @@ func runCreateDomainNonInteractive(f *cmdutil.Factory, opts *Options) error { } if err != nil { + s.Stop() return fmt.Errorf("add domain failed: %w", err) } s.Stop()