diff --git a/google/common_operation.go b/google/common_operation.go index 31ad8a16..3160b180 100644 --- a/google/common_operation.go +++ b/google/common_operation.go @@ -98,11 +98,15 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc { if !isRetryableError(err) { return nil, "", fmt.Errorf("Not retriable error: %s", err) } + + log.Printf("[DEBUG] Saw error polling for op, but dismissed as retriable: %s", err) if op == nil { return nil, "", fmt.Errorf("Cannot continue, Operation is nil. %s", err) } } + log.Printf("[DEBUG] working with op %#v", op) + // 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 { diff --git a/google/sqladmin_operation.go b/google/sqladmin_operation.go index fe9c2bd4..1e9990ef 100644 --- a/google/sqladmin_operation.go +++ b/google/sqladmin_operation.go @@ -3,6 +3,7 @@ package google import ( "bytes" "fmt" + "log" sqladmin "google.golang.org/api/sqladmin/v1beta4" ) @@ -14,7 +15,11 @@ type SqlAdminOperationWaiter struct { } func (w *SqlAdminOperationWaiter) State() string { - if w == nil || w.Op == nil { + if w == nil { + return "Operation Waiter is nil!" + } + + if w.Op == nil { return "Operation is nil!" } @@ -29,8 +34,13 @@ func (w *SqlAdminOperationWaiter) Error() error { } func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error { - var ok bool - w.Op, ok = op.(*sqladmin.Operation) + if op == nil { + // Starting as a log statement, this may be a useful error in the future + log.Printf("[DEBUG] attempted to set nil op") + } + + sqlOp, ok := op.(*sqladmin.Operation) + w.Op = sqlOp if !ok { return fmt.Errorf("Unable to set operation. Bad type!") } @@ -39,19 +49,30 @@ func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error { } func (w *SqlAdminOperationWaiter) QueryOp() (interface{}, error) { - if w == nil || w.Op == nil { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, waiter is unset or nil.") + } + + if 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 "" + if w == nil { + return "" } + + if w.Op == nil { + return "" + } + return w.Op.Name }