From d494ad245f825c75b073833f55a5f4b682f9f664 Mon Sep 17 00:00:00 2001 From: Miguel Mendoza Date: Tue, 30 Sep 2025 18:03:25 -0700 Subject: [PATCH] feat: allow LRO errors to bubble out when using --wait --- internal/client/connections/connectors.go | 23 +++++++++++++++++++++++ internal/client/connections/endpoints.go | 13 ++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/internal/client/connections/connectors.go b/internal/client/connections/connectors.go index 8f482123..2bd6faba 100644 --- a/internal/client/connections/connectors.go +++ b/internal/client/connections/connectors.go @@ -289,19 +289,24 @@ func Create(name string, content []byte, serviceAccountName string, serviceAccou operationId := filepath.Base(o.Name) clilog.Info.Printf("Checking connection status for %s in %d seconds\n", operationId, interval) + var lroError error stop := apiclient.Every(interval*time.Second, func(time.Time) bool { var respBody []byte + lroError = nil if respBody, err = GetOperation(operationId); err != nil { + lroError = err return false } if err = json.Unmarshal(respBody, &o); err != nil { + lroError = err return false } if o.Done { if o.Error != nil { + lroError = errors.New(o.Error.Message) clilog.Error.Printf("Connection completed with error: %s\n", o.Error.Message) } else { clilog.Info.Println("Connection completed successfully!") @@ -314,6 +319,11 @@ func Create(name string, content []byte, serviceAccountName string, serviceAccou }) <-stop + + if isBubbleLROErrorsEnabled() { + err = lroError + } + } return respBody, err @@ -1118,19 +1128,24 @@ func RepairEvent(name string, wait bool) (err error) { operationId := filepath.Base(o.Name) clilog.Info.Printf("Checking connection repair status for %s in %d seconds\n", operationId, interval) + var lroError error stop := apiclient.Every(interval*time.Second, func(time.Time) bool { var respBody []byte + lroError = nil if respBody, err = GetOperation(operationId); err != nil { + lroError = err return false } if err = json.Unmarshal(respBody, &o); err != nil { + lroError = err return false } if o.Done { if o.Error != nil { + lroError = errors.New(o.Error.Message) clilog.Error.Printf("Connection completed with error: %s\n", o.Error.Message) } else { clilog.Info.Println("Connection repair completed successfully!") @@ -1143,6 +1158,10 @@ func RepairEvent(name string, wait bool) (err error) { }) <-stop + + if isBubbleLROErrorsEnabled() { + err = lroError + } } return err } @@ -1176,3 +1195,7 @@ func isGoogleConnection(connectionName string) bool { } return false } + +func isBubbleLROErrorsEnabled() bool { + return os.Getenv("INTEGRATIONCLI_BUBBLE_LRO_ERRORS") == "1" +} diff --git a/internal/client/connections/endpoints.go b/internal/client/connections/endpoints.go index bcc99657..7307eb20 100644 --- a/internal/client/connections/endpoints.go +++ b/internal/client/connections/endpoints.go @@ -16,6 +16,7 @@ package connections import ( "encoding/json" + "errors" "fmt" "internal/apiclient" "internal/clilog" @@ -80,19 +81,24 @@ func CreateEndpoint(name string, serviceAttachment string, description string, w operationId := filepath.Base(o.Name) clilog.Info.Printf("Checking connection status for %s in %d seconds\n", operationId, interval) + var lroError error stop := apiclient.Every(interval*time.Second, func(time.Time) bool { var respBody []byte + lroError = nil if respBody, err = GetOperation(operationId); err != nil { + lroError = err return false } if err = json.Unmarshal(respBody, &o); err != nil { + lroError = err return false } if o.Done { if o.Error != nil { + lroError = errors.New(o.Error.Message) clilog.Error.Printf("Connection completed with error: %s\n", o.Error.Message) } else { clilog.Info.Println("Connection completed successfully!") @@ -105,8 +111,13 @@ func CreateEndpoint(name string, serviceAttachment string, description string, w }) <-stop + + if isBubbleLROErrorsEnabled() { + err = lroError + } } - return + + return respBody, err } // GetEndpoint