/
error.go
33 lines (29 loc) · 925 Bytes
/
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
package minio
import (
"fmt"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)
// NewResourceError creates a new error with the given msg argument.
func NewResourceError(msg string, resource string, err interface{}) diag.Diagnostics {
switch err := err.(type) {
case diag.Diagnostics:
return append(err, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("[FATAL] %s (%s)", msg, resource),
})
case error:
return diag.Errorf("[FATAL] %s (%s): %s", msg, resource, err)
default:
return diag.Errorf("[FATAL] %s (%s): %v", msg, resource, err)
}
}
// NewResourceErrorStr creates a new error with the given msg argument.
func NewResourceErrorStr(msg string, resource string, err interface{}) string {
diags := NewResourceError(msg, resource, err)
strs := make([]string, len(diags))
for _, d := range diags {
strs = append(strs, d.Summary)
}
return strings.Join(strs, ", ")
}