@@ -81,6 +81,18 @@ can be removed automatically by this program.`)
8181 token = flag .String ("token" , "" , "When set, the proxy uses this Bearer token for authorization." )
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.` )
84+
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
8496)
8597
8698const (
@@ -334,9 +346,12 @@ func gcloudProject() []string {
334346
335347 if err := cmd .Run (); err != nil {
336348 if strings .Contains (err .Error (), "executable file not found" ) {
337- // gcloud not installed; ignore the error
349+ // gcloud not found (probably not installed). Ignore the error but record
350+ // the status for later use.
351+ gcloudStatus = gcloudNotFound
338352 return nil
339353 }
354+ gcloudStatus = gcloudExecErr
340355 logging .Errorf ("Error detecting gcloud project: %v" , err )
341356 return nil
342357 }
@@ -348,6 +363,7 @@ func gcloudProject() []string {
348363 }
349364
350365 if err := json .Unmarshal (buf .Bytes (), & data ); err != nil {
366+ gcloudStatus = gcloudExecErr
351367 logging .Errorf ("Failed to unmarshal bytes from gcloud: %v" , err )
352368 logging .Errorf (" gcloud returned:\n %s" , buf )
353369 return nil
0 commit comments