-
Notifications
You must be signed in to change notification settings - Fork 0
/
append.go
45 lines (37 loc) · 1.23 KB
/
append.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package sdkdiag
import (
"fmt"
tfslices "github.com/cloudbuzzbyone/terraform-provider-appflow/internal/slices"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)
func AppendWarningf(diags diag.Diagnostics, format string, a ...any) diag.Diagnostics {
return append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: fmt.Sprintf(format, a...),
})
}
func AppendErrorf(diags diag.Diagnostics, format string, a ...any) diag.Diagnostics {
return append(diags, diag.Errorf(format, a...)...) // nosemgrep:ci.semgrep.pluginsdk.avoid-diag_Errorf
}
func AppendFromErr(diags diag.Diagnostics, err error) diag.Diagnostics {
if err == nil {
return diags
}
return append(diags, diag.FromErr(err)...) // nosemgrep:ci.semgrep.pluginsdk.avoid-diag_FromErr
}
func WrapDiagsf(orig diag.Diagnostics, format string, a ...any) diag.Diagnostics {
if len(orig) == 0 {
return orig
}
msg := fmt.Sprintf(format, a...)
return tfslices.ApplyToAll(orig, func(d diag.Diagnostic) diag.Diagnostic {
return diag.Diagnostic{
Severity: d.Severity,
Summary: fmt.Sprintf("%s: %s", msg, d.Summary),
Detail: d.Detail,
AttributePath: d.AttributePath,
}
})
}