@@ -10,13 +10,17 @@ import (
10
10
var _ function.Function = NameFromIdFunction {}
11
11
12
12
func NewNameFromIdFunction () function.Function {
13
- return & NameFromIdFunction {}
13
+ return & NameFromIdFunction {
14
+ name : "name_from_id" ,
15
+ }
14
16
}
15
17
16
- type NameFromIdFunction struct {}
18
+ type NameFromIdFunction struct {
19
+ name string
20
+ }
17
21
18
22
func (f NameFromIdFunction ) Metadata (ctx context.Context , req function.MetadataRequest , resp * function.MetadataResponse ) {
19
- resp .Name = "name_from_id"
23
+ resp .Name = f . name
20
24
}
21
25
22
26
func (f NameFromIdFunction ) Definition (ctx context.Context , req function.DefinitionRequest , resp * function.DefinitionResponse ) {
@@ -36,9 +40,8 @@ func (f NameFromIdFunction) Definition(ctx context.Context, req function.Definit
36
40
func (f NameFromIdFunction ) Run (ctx context.Context , req function.RunRequest , resp * function.RunResponse ) {
37
41
// Load arguments from function call
38
42
var arg0 string
39
- resp .Diagnostics .Append (req .Arguments .GetArgument (ctx , 0 , & arg0 )... )
40
-
41
- if resp .Diagnostics .HasError () {
43
+ resp .Error = function .ConcatFuncErrors (req .Arguments .GetArgument (ctx , 0 , & arg0 ))
44
+ if resp .Error != nil {
42
45
return
43
46
}
44
47
@@ -48,12 +51,12 @@ func (f NameFromIdFunction) Run(ctx context.Context, req function.RunRequest, re
48
51
pattern := "resourceType/{name}$" // Human-readable pseudo-regex pattern used in errors and warnings
49
52
50
53
// Validate input
51
- ValidateElementFromIdArguments (arg0 , regex , pattern , resp )
52
- if resp .Diagnostics . HasError () {
54
+ resp . Error = function . ConcatFuncErrors ( ValidateElementFromIdArguments (ctx , arg0 , regex , pattern , f . name ) )
55
+ if resp .Error != nil {
53
56
return
54
57
}
55
58
56
59
// Get and return element from input string
57
60
name := GetElementFromId (arg0 , regex , template )
58
- resp .Diagnostics . Append (resp .Result .Set (ctx , name )... )
61
+ resp .Error = function . ConcatFuncErrors (resp .Result .Set (ctx , name ))
59
62
}
0 commit comments