-
Notifications
You must be signed in to change notification settings - Fork 32
/
attribute_path_error.go
46 lines (37 loc) · 1019 Bytes
/
attribute_path_error.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
42
43
44
45
46
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tftypes
import (
"fmt"
)
// AttributePathError represents an error associated with part of a
// tftypes.Value, indicated by the Path property.
type AttributePathError struct {
Path *AttributePath
err error
}
// Equal returns true if two AttributePathErrors are semantically equal. To be
// considered equal, they must have the same path and if errors are set, the
// strings returned by their `Error()` methods must match.
func (a AttributePathError) Equal(o AttributePathError) bool {
if !a.Path.Equal(o.Path) {
return false
}
if (a.err == nil && o.err != nil) || (a.err != nil && o.err == nil) {
return false
}
if a.err == nil {
return true
}
return a.err.Error() == o.err.Error()
}
func (a AttributePathError) Error() string {
var path string
if len(a.Path.Steps()) > 0 {
path = a.Path.String() + ": "
}
return fmt.Sprintf("%s%s", path, a.err)
}
func (a AttributePathError) Unwrap() error {
return a.err
}