-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
41 lines (35 loc) · 1.26 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package tfresource
import (
"errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
// NotFound returns true if the error represents a "resource not found" condition.
// Specifically, NotFound returns true if the error or a wrapped error is of type
// resource.NotFoundError.
func NotFound(err error) bool {
var e *resource.NotFoundError // nosemgrep:ci.is-not-found-error
return errors.As(err, &e)
}
// TimedOut returns true if the error represents a "wait timed out" condition.
// Specifically, TimedOut returns true if the error matches all these conditions:
// * err is of type resource.TimeoutError
// * TimeoutError.LastError is nil
func TimedOut(err error) bool {
// This explicitly does *not* match wrapped TimeoutErrors
timeoutErr, ok := err.(*resource.TimeoutError) //nolint:errorlint // Explicitly does *not* match wrapped TimeoutErrors
return ok && timeoutErr.LastError == nil
}
// SetLastError sets the LastError field on the error if supported.
// If lastErr is nil it is ignored.
func SetLastError(err, lastErr error) {
switch err := err.(type) {
case *resource.TimeoutError:
if err.LastError == nil {
err.LastError = lastErr
}
case *resource.UnexpectedStateError:
if err.LastError == nil {
err.LastError = lastErr
}
}
}