Skip to content

Commit

Permalink
ZEA-3791: nil pointer issue in zeabur/cli (#105)
Browse files Browse the repository at this point in the history
* fix: Handle service == nil case

If there is no (matched) services in projects, we let users reselect the project.

* docs(selector): Document triple nil behavior
  • Loading branch information
pan93412 authored Aug 9, 2024
1 parent 98ba157 commit 9c940dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/fill/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func (f *paramFiller) Service(projectID, serviceID *string) (changed bool, err e
if err != nil {
return false, err
}
if service == nil {
fmt.Printf("Project %s contains no services.\n\n", *projectID)
*projectID = ""
return f.Service(projectID, serviceID)
}

*serviceID = service.ID

Expand Down Expand Up @@ -195,6 +200,11 @@ func (f *paramFiller) ServiceByName(opt ServiceByNameOptions) (changed bool, err
if err != nil {
return false, err
}
if service == nil {
fmt.Printf("Project %s contains no matched services.\n\n", projectCtx.GetProject().GetID())
opt.ProjectCtx.ClearAll()
return f.ServiceByName(opt)
}

*serviceID = service.GetID()
*serviceName = service.GetName()
Expand Down
4 changes: 4 additions & 0 deletions pkg/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ type SelectServiceOptions struct {
FilterFunc func(service *model.Service) bool
}

// SelectService selects a service from the project.
//
// Note that it may returns nil (with no error) if there is no service in the project.
// If user selected "Create a new service", it also returns a nil.
func (s *selector) SelectService(opt SelectServiceOptions) (zcontext.BasicInfo, *model.Service, error) {
projectID := opt.ProjectID
auto := opt.Auto
Expand Down

0 comments on commit 9c940dd

Please sign in to comment.