github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/helper/resource/error.go (about) 1 package resource 2 3 import ( 4 "fmt" 5 "strings" 6 "time" 7 ) 8 9 type NotFoundError struct { 10 LastError error 11 LastRequest interface{} 12 LastResponse interface{} 13 Message string 14 Retries int 15 } 16 17 func (e *NotFoundError) Error() string { 18 if e.Message != "" { 19 return e.Message 20 } 21 22 return "couldn't find resource" 23 } 24 25 // UnexpectedStateError is returned when Refresh returns a state that's neither in Target nor Pending 26 type UnexpectedStateError struct { 27 LastError error 28 State string 29 ExpectedState []string 30 } 31 32 func (e *UnexpectedStateError) Error() string { 33 return fmt.Sprintf( 34 "unexpected state '%s', wanted target '%s'. last error: %s", 35 e.State, 36 strings.Join(e.ExpectedState, ", "), 37 e.LastError, 38 ) 39 } 40 41 // TimeoutError is returned when WaitForState times out 42 type TimeoutError struct { 43 LastError error 44 LastState string 45 Timeout time.Duration 46 ExpectedState []string 47 } 48 49 func (e *TimeoutError) Error() string { 50 expectedState := "resource to be gone" 51 if len(e.ExpectedState) > 0 { 52 expectedState = fmt.Sprintf("state to become '%s'", strings.Join(e.ExpectedState, ", ")) 53 } 54 55 extraInfo := make([]string, 0) 56 if e.LastState != "" { 57 extraInfo = append(extraInfo, fmt.Sprintf("last state: '%s'", e.LastState)) 58 } 59 if e.Timeout > 0 { 60 extraInfo = append(extraInfo, fmt.Sprintf("timeout: %s", e.Timeout.String())) 61 } 62 63 suffix := "" 64 if len(extraInfo) > 0 { 65 suffix = fmt.Sprintf(" (%s)", strings.Join(extraInfo, ", ")) 66 } 67 68 if e.LastError != nil { 69 return fmt.Sprintf("timeout while waiting for %s%s: %s", 70 expectedState, suffix, e.LastError) 71 } 72 73 return fmt.Sprintf("timeout while waiting for %s%s", 74 expectedState, suffix) 75 }