@@ -82,8 +82,17 @@ can be removed automatically by this program.`)
8282 tokenFile = flag .String ("credential_file" , "" , `If provided, this json file will be used to retrieve Service Account credentials.
8383You may set the GOOGLE_APPLICATION_CREDENTIALS environment variable for the same effect.` )
8484
85- // Set when gcloud execution failed.
86- gcloudErrStr string
85+ // Set to non-default value when gcloud execution failed.
86+ gcloudStatus gcloudStatusCode
87+ )
88+
89+ type gcloudStatusCode int
90+
91+ const (
92+ gcloudOk gcloudStatusCode = iota
93+ gcloudNotFound
94+ // generic execution failure error not specified above.
95+ gcloudExecErr
8796)
8897
8998const (
@@ -338,10 +347,12 @@ func gcloudProject() []string {
338347
339348 if err := cmd .Run (); err != nil {
340349 if strings .Contains (err .Error (), "executable file not found" ) {
341- gcloudErrStr = "gcloud could not be found in the system path"
350+ // gcloud not found (probably not installed). Ignore the error but record
351+ // the status for later use.
352+ gcloudStatus = gcloudNotFound
342353 return nil
343354 }
344- gcloudErrStr = gcloudResultErrStr
355+ gcloudStatus = gcloudExecErr
345356 logging .Errorf ("Error detecting gcloud project: %v" , err )
346357 return nil
347358 }
@@ -353,7 +364,7 @@ func gcloudProject() []string {
353364 }
354365
355366 if err := json .Unmarshal (buf .Bytes (), & data ); err != nil {
356- gcloudErrStr = gcloudResultErrStr
367+ gcloudStatus = gcloudExecErr
357368 logging .Errorf ("Failed to unmarshal bytes from gcloud: %v" , err )
358369 logging .Errorf (" gcloud returned:\n %s" , buf )
359370 return nil
0 commit comments