Skip to content

Commit 3d95861

Browse files
authored
Improve environment error messages during cortex get (#1292)
1 parent 2f938a3 commit 3d95861

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

cli/cmd/get.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,26 @@ func getAPIsInAllEnvironments() (string, error) {
189189
out := ""
190190

191191
if len(allRealtimeAPIs) == 0 && len(allBatchAPIs) == 0 && len(allTrafficSplitters) == 0 {
192-
if len(errorsMap) == 1 {
193-
// Print the error if there is just one
194-
exit.Error(errors.FirstErrorInMap(errorsMap))
195-
}
196-
// if all envs errored, skip "no apis are deployed" since it's misleading
192+
// check if any environments errorred
197193
if len(errorsMap) != len(cliConfig.Environments) {
198-
out += console.Bold("no apis are deployed") + "\n"
194+
if len(errorsMap) == 0 {
195+
return console.Bold("no apis are deployed"), nil
196+
}
197+
198+
var successfulEnvs []string
199+
for _, env := range cliConfig.Environments {
200+
if _, ok := errorsMap[env.Name]; !ok {
201+
successfulEnvs = append(successfulEnvs, env.Name)
202+
}
203+
}
204+
fmt.Println(console.Bold(fmt.Sprintf("no apis are deployed in %s: %s", s.PluralS("environment", len(successfulEnvs)), s.StrsAnd(successfulEnvs))) + "\n")
205+
}
206+
207+
// Print the first error
208+
for name, err := range errorsMap {
209+
if err != nil {
210+
exit.Error(errors.Wrap(err, "env "+name))
211+
}
199212
}
200213
} else {
201214
if len(allBatchAPIs) > 0 {

0 commit comments

Comments
 (0)