...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package krmtotf
16
17 import (
18 "errors"
19 "fmt"
20 "strings"
21
22 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
23 )
24
25 func NewErrorFromDiagnostics(diagnostics diag.Diagnostics) error {
26 if !diagnostics.HasError() {
27 return nil
28 }
29 msgs := make([]string, 0)
30 for _, d := range diagnostics {
31 if d.Severity == diag.Error {
32
33 if d.Detail == "" {
34 msgs = append(msgs, fmt.Sprintf("summary: %v", d.Summary))
35 } else {
36 msgs = append(msgs, fmt.Sprintf("summary: %v, detail: %v", d.Summary, d.Detail))
37 }
38 }
39 }
40 return errors.New(strings.Join(msgs, "\n"))
41 }
42
View as plain text