diff --git a/google/common_operation.go b/google/common_operation.go index 5e693eac..e595839e 100644 --- a/google/common_operation.go +++ b/google/common_operation.go @@ -42,6 +42,10 @@ type CommonOperationWaiter struct { } func (w *CommonOperationWaiter) State() string { + if w == nil { + return fmt.Sprintf("Operation is nil!") + } + return fmt.Sprintf("done: %v", w.Op.Done) } @@ -60,6 +64,10 @@ func (w *CommonOperationWaiter) SetOp(op interface{}) error { } func (w *CommonOperationWaiter) OpName() string { + if w == nil { + return "" + } + return w.Op.Name } @@ -86,14 +94,19 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc { op, err := w.QueryOp() // If we got a non-retryable error, return it. - if err != nil && !isRetryableError(err) { - return nil, "", err + if err != nil { + if !isRetryableError(err) { + return nil, "", fmt.Errorf("Not retriable error: %s", err) + } + if op == nil { + return nil, "", fmt.Errorf("Cannot continue, Operation is nil. %s", err) + } } // Try to set the operation (so we can check it's Error/State), // and fail if we can't. if err = w.SetOp(op); err != nil { - return nil, "", err + return nil, "", fmt.Errorf("Cannot continue %s", err) } // Fail if the operation object contains an error. diff --git a/google/compute_operation.go b/google/compute_operation.go index 69b19746..b8540381 100644 --- a/google/compute_operation.go +++ b/google/compute_operation.go @@ -2,6 +2,7 @@ package google import ( "bytes" + "fmt" computeBeta "google.golang.org/api/compute/v0.beta" "google.golang.org/api/compute/v1" @@ -14,18 +15,26 @@ type ComputeOperationWaiter struct { } func (w *ComputeOperationWaiter) State() string { + if w == nil || w.Op == nil { + return fmt.Sprintf("Operation is nil!") + } + return w.Op.Status } func (w *ComputeOperationWaiter) Error() error { - if w.Op.Error != nil { + if w != nil && w.Op != nil && w.Op.Error != nil { return ComputeOperationError(*w.Op.Error) } return nil } func (w *ComputeOperationWaiter) SetOp(op interface{}) error { - w.Op = op.(*compute.Operation) + var ok bool + w.Op, ok = op.(*compute.Operation) + if !ok { + return fmt.Errorf("Unable to set operation. Bad type!") + } return nil } @@ -41,6 +50,10 @@ func (w *ComputeOperationWaiter) QueryOp() (interface{}, error) { } func (w *ComputeOperationWaiter) OpName() string { + if w == nil || w.Op == nil { + return " Compute Op" + } + return w.Op.Name }