diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/terraform/helper/resource/error.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/resource/error.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/resource/error.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/resource/error.go b/vendor/github.com/hashicorp/terraform/helper/resource/error.go new file mode 100644 index 0000000..7ee2161 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/helper/resource/error.go | |||
@@ -0,0 +1,79 @@ | |||
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 | if e.Retries > 0 { | ||
23 | return fmt.Sprintf("couldn't find resource (%d retries)", e.Retries) | ||
24 | } | ||
25 | |||
26 | return "couldn't find resource" | ||
27 | } | ||
28 | |||
29 | // UnexpectedStateError is returned when Refresh returns a state that's neither in Target nor Pending | ||
30 | type UnexpectedStateError struct { | ||
31 | LastError error | ||
32 | State string | ||
33 | ExpectedState []string | ||
34 | } | ||
35 | |||
36 | func (e *UnexpectedStateError) Error() string { | ||
37 | return fmt.Sprintf( | ||
38 | "unexpected state '%s', wanted target '%s'. last error: %s", | ||
39 | e.State, | ||
40 | strings.Join(e.ExpectedState, ", "), | ||
41 | e.LastError, | ||
42 | ) | ||
43 | } | ||
44 | |||
45 | // TimeoutError is returned when WaitForState times out | ||
46 | type TimeoutError struct { | ||
47 | LastError error | ||
48 | LastState string | ||
49 | Timeout time.Duration | ||
50 | ExpectedState []string | ||
51 | } | ||
52 | |||
53 | func (e *TimeoutError) Error() string { | ||
54 | expectedState := "resource to be gone" | ||
55 | if len(e.ExpectedState) > 0 { | ||
56 | expectedState = fmt.Sprintf("state to become '%s'", strings.Join(e.ExpectedState, ", ")) | ||
57 | } | ||
58 | |||
59 | extraInfo := make([]string, 0) | ||
60 | if e.LastState != "" { | ||
61 | extraInfo = append(extraInfo, fmt.Sprintf("last state: '%s'", e.LastState)) | ||
62 | } | ||
63 | if e.Timeout > 0 { | ||
64 | extraInfo = append(extraInfo, fmt.Sprintf("timeout: %s", e.Timeout.String())) | ||
65 | } | ||
66 | |||
67 | suffix := "" | ||
68 | if len(extraInfo) > 0 { | ||
69 | suffix = fmt.Sprintf(" (%s)", strings.Join(extraInfo, ", ")) | ||
70 | } | ||
71 | |||
72 | if e.LastError != nil { | ||
73 | return fmt.Sprintf("timeout while waiting for %s%s: %s", | ||
74 | expectedState, suffix, e.LastError) | ||
75 | } | ||
76 | |||
77 | return fmt.Sprintf("timeout while waiting for %s%s", | ||
78 | expectedState, suffix) | ||
79 | } | ||