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