-
Notifications
You must be signed in to change notification settings - Fork 0
/
diags.go
115 lines (98 loc) · 3.65 KB
/
diags.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package reflect
import (
"fmt"
"reflect"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
func toTerraform5ValueErrorDiag(err error, path path.Path) diag.DiagnosticWithPath {
return diag.NewAttributeErrorDiagnostic(
path,
"Value Conversion Error",
"An unexpected error was encountered trying to convert into a Terraform value. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(),
)
}
func toTerraformValueErrorDiag(err error, path path.Path) diag.DiagnosticWithPath {
return diag.NewAttributeErrorDiagnostic(
path,
"Value Conversion Error",
"An unexpected error was encountered trying to convert the Attribute value into a Terraform value. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(),
)
}
func validateValueErrorDiag(err error, path path.Path) diag.DiagnosticWithPath {
return diag.NewAttributeErrorDiagnostic(
path,
"Value Conversion Error",
"An unexpected error was encountered trying to validate the Terraform value type. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(),
)
}
func valueFromTerraformErrorDiag(err error, path path.Path) diag.DiagnosticWithPath {
return diag.NewAttributeErrorDiagnostic(
path,
"Value Conversion Error",
"An unexpected error was encountered trying to convert the Terraform value. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(),
)
}
type DiagIntoIncompatibleType struct {
Val tftypes.Value
TargetType reflect.Type
Err error
}
func (d DiagIntoIncompatibleType) Severity() diag.Severity {
return diag.SeverityError
}
func (d DiagIntoIncompatibleType) Summary() string {
return "Value Conversion Error"
}
func (d DiagIntoIncompatibleType) Detail() string {
return fmt.Sprintf("An unexpected error was encountered trying to convert %T into %s. This is always an error in the provider. Please report the following to the provider developer:\n\n%s", d.Val, d.TargetType, d.Err.Error())
}
func (d DiagIntoIncompatibleType) Equal(o diag.Diagnostic) bool {
od, ok := o.(DiagIntoIncompatibleType)
if !ok {
return false
}
if !d.Val.Equal(od.Val) {
return false
}
if d.TargetType != od.TargetType {
return false
}
if d.Err.Error() != od.Err.Error() {
return false
}
return true
}
type DiagNewAttributeValueIntoWrongType struct {
ValType reflect.Type
TargetType reflect.Type
SchemaType attr.Type
}
func (d DiagNewAttributeValueIntoWrongType) Severity() diag.Severity {
return diag.SeverityError
}
func (d DiagNewAttributeValueIntoWrongType) Summary() string {
return "Value Conversion Error"
}
func (d DiagNewAttributeValueIntoWrongType) Detail() string {
return fmt.Sprintf("An unexpected error was encountered trying to convert into a Terraform value. This is always an error in the provider. Please report the following to the provider developer:\n\nCannot use attr.Value %s, only %s is supported because %T is the type in the schema", d.TargetType, d.ValType, d.SchemaType)
}
func (d DiagNewAttributeValueIntoWrongType) Equal(o diag.Diagnostic) bool {
od, ok := o.(DiagNewAttributeValueIntoWrongType)
if !ok {
return false
}
if d.ValType != od.ValType {
return false
}
if d.TargetType != od.TargetType {
return false
}
if !d.SchemaType.Equal(od.SchemaType) {
return false
}
return true
}