diff --git a/google-beta/appengine_operation.go b/google-beta/appengine_operation.go index 48288545a0..ca3eb26dde 100644 --- a/google-beta/appengine_operation.go +++ b/google-beta/appengine_operation.go @@ -18,6 +18,9 @@ type AppEngineOperationWaiter struct { } func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } matches := appEngineOperationIdRegexp.FindStringSubmatch(w.Op.Name) if len(matches) != 2 { return nil, fmt.Errorf("Expected %d results of parsing operation name, got %d from %s", 2, len(matches), w.Op.Name) diff --git a/google-beta/cloudfunctions_operation.go b/google-beta/cloudfunctions_operation.go index 71d3d8a893..ba39814c86 100644 --- a/google-beta/cloudfunctions_operation.go +++ b/google-beta/cloudfunctions_operation.go @@ -1,6 +1,8 @@ package google import ( + "fmt" + "google.golang.org/api/cloudfunctions/v1" ) @@ -10,6 +12,9 @@ type CloudFunctionsOperationWaiter struct { } func (w *CloudFunctionsOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/common_operation.go b/google-beta/common_operation.go index e595839e21..31ad8a1662 100644 --- a/google-beta/common_operation.go +++ b/google-beta/common_operation.go @@ -50,7 +50,7 @@ func (w *CommonOperationWaiter) State() string { } func (w *CommonOperationWaiter) Error() error { - if w.Op.Error != nil { + if w != nil && w.Op.Error != nil { return fmt.Errorf("Error code %v, message: %s", w.Op.Error.Code, w.Op.Error.Message) } return nil diff --git a/google-beta/composer_operation.go b/google-beta/composer_operation.go index 4442980934..ce222858b2 100644 --- a/google-beta/composer_operation.go +++ b/google-beta/composer_operation.go @@ -1,6 +1,8 @@ package google import ( + "fmt" + composer "google.golang.org/api/composer/v1beta1" ) @@ -10,6 +12,9 @@ type ComposerOperationWaiter struct { } func (w *ComposerOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/compute_operation.go b/google-beta/compute_operation.go index b8540381c8..992d596154 100644 --- a/google-beta/compute_operation.go +++ b/google-beta/compute_operation.go @@ -16,7 +16,7 @@ type ComputeOperationWaiter struct { func (w *ComputeOperationWaiter) State() string { if w == nil || w.Op == nil { - return fmt.Sprintf("Operation is nil!") + return "" } return w.Op.Status @@ -39,6 +39,9 @@ func (w *ComputeOperationWaiter) SetOp(op interface{}) error { } func (w *ComputeOperationWaiter) QueryOp() (interface{}, error) { + if w == nil || w.Op == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } if w.Op.Zone != "" { zone := GetResourceNameFromSelfLink(w.Op.Zone) return w.Service.ZoneOperations.Get(w.Project, zone, w.Op.Name).Do() diff --git a/google-beta/container_operation.go b/google-beta/container_operation.go index 82c2933f69..188cf884ec 100644 --- a/google-beta/container_operation.go +++ b/google-beta/container_operation.go @@ -3,7 +3,7 @@ package google import ( "fmt" - "google.golang.org/api/container/v1beta1" + container "google.golang.org/api/container/v1beta1" ) type ContainerOperationWaiter struct { @@ -14,28 +14,41 @@ type ContainerOperationWaiter struct { } func (w *ContainerOperationWaiter) State() string { + if w == nil || w.Op == nil { + return "" + } return w.Op.Status } func (w *ContainerOperationWaiter) Error() error { - if w.Op.StatusMessage != "" { + if w != nil && w.Op != nil { return fmt.Errorf(w.Op.StatusMessage) } return nil } func (w *ContainerOperationWaiter) SetOp(op interface{}) error { - w.Op = op.(*container.Operation) + var ok bool + w.Op, ok = op.(*container.Operation) + if !ok { + return fmt.Errorf("Unable to set operation. Bad type!") + } return nil } func (w *ContainerOperationWaiter) QueryOp() (interface{}, error) { + if w == nil || w.Op == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } name := fmt.Sprintf("projects/%s/locations/%s/operations/%s", w.Project, w.Location, w.Op.Name) return w.Service.Projects.Locations.Operations.Get(name).Do() } func (w *ContainerOperationWaiter) OpName() string { + if w == nil || w.Op == nil { + return "" + } return w.Op.Name } diff --git a/google-beta/dataproc_cluster_operation.go b/google-beta/dataproc_cluster_operation.go index 5172a34718..0cbd32c951 100644 --- a/google-beta/dataproc_cluster_operation.go +++ b/google-beta/dataproc_cluster_operation.go @@ -1,6 +1,8 @@ package google import ( + "fmt" + "google.golang.org/api/dataproc/v1" ) @@ -10,6 +12,9 @@ type DataprocClusterOperationWaiter struct { } func (w *DataprocClusterOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Projects.Regions.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/dataproc_job_operation.go b/google-beta/dataproc_job_operation.go index 6e1c56e1a8..ce3cab01ee 100644 --- a/google-beta/dataproc_job_operation.go +++ b/google-beta/dataproc_job_operation.go @@ -1,6 +1,7 @@ package google import ( + "fmt" "net/http" "google.golang.org/api/dataproc/v1" @@ -15,6 +16,9 @@ type DataprocJobOperationWaiter struct { } func (w *DataprocJobOperationWaiter) State() string { + if w == nil { + return "" + } return w.Status } @@ -32,6 +36,9 @@ func (w *DataprocJobOperationWaiter) SetOp(job interface{}) error { } func (w *DataprocJobOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } job, err := w.Service.Projects.Regions.Jobs.Get(w.ProjectId, w.Region, w.JobId).Do() if job != nil { w.Status = job.Status.State @@ -40,6 +47,9 @@ func (w *DataprocJobOperationWaiter) QueryOp() (interface{}, error) { } func (w *DataprocJobOperationWaiter) OpName() string { + if w == nil { + return "" + } return w.JobId } @@ -74,6 +84,9 @@ func (w *DataprocDeleteJobOperationWaiter) TargetStates() []string { } func (w *DataprocDeleteJobOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } job, err := w.Service.Projects.Regions.Jobs.Get(w.ProjectId, w.Region, w.JobId).Do() if err != nil { if isGoogleApiErrorWithCode(err, http.StatusNotFound) { diff --git a/google-beta/redis_operation.go b/google-beta/redis_operation.go index b907cf5c02..14ee7cd22a 100644 --- a/google-beta/redis_operation.go +++ b/google-beta/redis_operation.go @@ -1,7 +1,9 @@ package google import ( - "google.golang.org/api/redis/v1beta1" + "fmt" + + redis "google.golang.org/api/redis/v1beta1" ) type RedisOperationWaiter struct { @@ -10,6 +12,9 @@ type RedisOperationWaiter struct { } func (w *RedisOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/resourcemanager_operation.go b/google-beta/resourcemanager_operation.go index 5df249357e..55444041a9 100644 --- a/google-beta/resourcemanager_operation.go +++ b/google-beta/resourcemanager_operation.go @@ -1,6 +1,8 @@ package google import ( + "fmt" + "google.golang.org/api/cloudresourcemanager/v1" resourceManagerV2Beta1 "google.golang.org/api/cloudresourcemanager/v2beta1" ) @@ -11,6 +13,9 @@ type ResourceManagerOperationWaiter struct { } func (w *ResourceManagerOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/serviceman_operation.go b/google-beta/serviceman_operation.go index 3f87ae3131..078a89139f 100644 --- a/google-beta/serviceman_operation.go +++ b/google-beta/serviceman_operation.go @@ -1,6 +1,8 @@ package google import ( + "fmt" + "google.golang.org/api/googleapi" "google.golang.org/api/servicemanagement/v1" ) @@ -11,6 +13,9 @@ type ServiceManagementOperationWaiter struct { } func (w *ServiceManagementOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/serviceusage_operation.go b/google-beta/serviceusage_operation.go index bb8e90ab80..e595fd4c95 100644 --- a/google-beta/serviceusage_operation.go +++ b/google-beta/serviceusage_operation.go @@ -1,7 +1,9 @@ package google import ( - "google.golang.org/api/serviceusage/v1beta1" + "fmt" + + serviceusage "google.golang.org/api/serviceusage/v1beta1" ) type ServiceUsageOperationWaiter struct { @@ -10,6 +12,9 @@ type ServiceUsageOperationWaiter struct { } func (w *ServiceUsageOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/spanner_instance_operation.go b/google-beta/spanner_instance_operation.go index 2831cc4833..d90dd50a1f 100644 --- a/google-beta/spanner_instance_operation.go +++ b/google-beta/spanner_instance_operation.go @@ -1,6 +1,8 @@ package google import ( + "fmt" + "google.golang.org/api/spanner/v1" ) @@ -10,6 +12,9 @@ type SpannerInstanceOperationWaiter struct { } func (w *SpannerInstanceOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } return w.Service.Projects.Instances.Operations.Get(w.Op.Name).Do() } diff --git a/google-beta/sqladmin_operation.go b/google-beta/sqladmin_operation.go index 635a6eb237..fe9c2bd402 100644 --- a/google-beta/sqladmin_operation.go +++ b/google-beta/sqladmin_operation.go @@ -2,8 +2,9 @@ package google import ( "bytes" + "fmt" - "google.golang.org/api/sqladmin/v1beta4" + sqladmin "google.golang.org/api/sqladmin/v1beta4" ) type SqlAdminOperationWaiter struct { @@ -13,26 +14,44 @@ type SqlAdminOperationWaiter struct { } func (w *SqlAdminOperationWaiter) State() string { + if w == nil || w.Op == nil { + return "Operation is nil!" + } + return w.Op.Status } func (w *SqlAdminOperationWaiter) Error() error { - if w.Op.Error != nil { + if w != nil && w.Op != nil && w.Op.Error != nil { return SqlAdminOperationError(*w.Op.Error) } return nil } func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error { - w.Op = op.(*sqladmin.Operation) + var ok bool + w.Op, ok = op.(*sqladmin.Operation) + if !ok { + return fmt.Errorf("Unable to set operation. Bad type!") + } + return nil } func (w *SqlAdminOperationWaiter) QueryOp() (interface{}, error) { + if w == nil || w.Op == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } + if w.Service == nil { + return nil, fmt.Errorf("Cannot query operation, service is nil.") + } return w.Service.Operations.Get(w.Project, w.Op.Name).Do() } func (w *SqlAdminOperationWaiter) OpName() string { + if w == nil || w.Op == nil { + return "" + } return w.Op.Name }