2016-03-15 14:01:50 +01:00
|
|
|
package resource
|
|
|
|
|
2016-06-02 01:50:43 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2016-09-15 11:53:25 +02:00
|
|
|
"time"
|
2016-06-02 01:50:43 +02:00
|
|
|
)
|
|
|
|
|
2016-03-15 14:01:50 +01:00
|
|
|
type NotFoundError struct {
|
|
|
|
LastError error
|
|
|
|
LastRequest interface{}
|
|
|
|
LastResponse interface{}
|
|
|
|
Message string
|
|
|
|
Retries int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *NotFoundError) Error() string {
|
|
|
|
if e.Message != "" {
|
|
|
|
return e.Message
|
|
|
|
}
|
|
|
|
|
|
|
|
return "couldn't find resource"
|
|
|
|
}
|
2016-06-02 01:50:43 +02:00
|
|
|
|
|
|
|
// UnexpectedStateError is returned when Refresh returns a state that's neither in Target nor Pending
|
|
|
|
type UnexpectedStateError struct {
|
|
|
|
LastError error
|
|
|
|
State string
|
|
|
|
ExpectedState []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *UnexpectedStateError) Error() string {
|
|
|
|
return fmt.Sprintf(
|
|
|
|
"unexpected state '%s', wanted target '%s'. last error: %s",
|
|
|
|
e.State,
|
|
|
|
strings.Join(e.ExpectedState, ", "),
|
|
|
|
e.LastError,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TimeoutError is returned when WaitForState times out
|
|
|
|
type TimeoutError struct {
|
|
|
|
LastError error
|
2016-08-27 22:25:14 +02:00
|
|
|
LastState string
|
2016-09-15 11:53:25 +02:00
|
|
|
Timeout time.Duration
|
2016-06-02 01:50:43 +02:00
|
|
|
ExpectedState []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *TimeoutError) Error() string {
|
2016-08-27 22:25:14 +02:00
|
|
|
expectedState := "resource to be gone"
|
|
|
|
if len(e.ExpectedState) > 0 {
|
|
|
|
expectedState = fmt.Sprintf("state to become '%s'", strings.Join(e.ExpectedState, ", "))
|
|
|
|
}
|
|
|
|
|
2016-09-15 11:53:25 +02:00
|
|
|
extraInfo := make([]string, 0)
|
2016-08-27 22:25:14 +02:00
|
|
|
if e.LastState != "" {
|
2016-09-15 11:53:25 +02:00
|
|
|
extraInfo = append(extraInfo, fmt.Sprintf("last state: '%s'", e.LastState))
|
|
|
|
}
|
|
|
|
if e.Timeout > 0 {
|
|
|
|
extraInfo = append(extraInfo, fmt.Sprintf("timeout: %s", e.Timeout.String()))
|
|
|
|
}
|
|
|
|
|
|
|
|
suffix := ""
|
|
|
|
if len(extraInfo) > 0 {
|
|
|
|
suffix = fmt.Sprintf(" (%s)", strings.Join(extraInfo, ", "))
|
2016-08-27 22:25:14 +02:00
|
|
|
}
|
|
|
|
|
2016-07-21 01:18:40 +02:00
|
|
|
if e.LastError != nil {
|
2016-08-27 22:25:14 +02:00
|
|
|
return fmt.Sprintf("timeout while waiting for %s%s: %s",
|
2016-09-15 11:53:25 +02:00
|
|
|
expectedState, suffix, e.LastError)
|
2016-07-21 01:18:40 +02:00
|
|
|
}
|
2016-08-22 10:34:32 +02:00
|
|
|
|
2016-08-27 22:25:14 +02:00
|
|
|
return fmt.Sprintf("timeout while waiting for %s%s",
|
2016-09-15 11:53:25 +02:00
|
|
|
expectedState, suffix)
|
2016-06-02 01:50:43 +02:00
|
|
|
}
|