Skip to content

Commit 6168f05

Browse files
authored
show available projects on project not found error (#777)
1 parent 43c8e51 commit 6168f05

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

cmd/lk/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,5 @@ func setDefaultProject(ctx context.Context, cmd *cli.Command) error {
307307
return nil
308308
}
309309

310-
return errors.New("project not found")
310+
return config.ProjectNotFoundError(cliConfig.Projects)
311311
}

pkg/config/config.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func LoadProjectBySubdomain(subdomain string) (*ProjectConfig, error) {
7777
}
7878
}
7979

80-
return nil, errors.New("project not found")
80+
return nil, ProjectNotFoundError(conf.Projects)
8181
}
8282

8383
func LoadProject(name string) (*ProjectConfig, error) {
@@ -92,7 +92,18 @@ func LoadProject(name string) (*ProjectConfig, error) {
9292
}
9393
}
9494

95-
return nil, errors.New("project not found")
95+
return nil, ProjectNotFoundError(conf.Projects)
96+
}
97+
98+
func ProjectNotFoundError(projects []ProjectConfig) error {
99+
if len(projects) == 0 {
100+
return errors.New("project not found. No projects configured, use `lk cloud auth` or `lk project add` to add a new project")
101+
}
102+
names := make([]string, len(projects))
103+
for i, p := range projects {
104+
names[i] = p.Name
105+
}
106+
return fmt.Errorf("project not found. Available projects: %s", strings.Join(names, ", "))
96107
}
97108

98109
// LoadOrCreate loads config file from ~/.livekit/cli-config.yaml

0 commit comments

Comments
 (0)