-
Notifications
You must be signed in to change notification settings - Fork 263
/
error_and_warnings.go
50 lines (42 loc) · 1.07 KB
/
error_and_warnings.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
package modconfig
import (
"github.com/hashicorp/hcl/v2"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe/pkg/error_helpers"
"github.com/turbot/steampipe/sperr"
)
type ErrorAndWarnings struct {
Error error
Warnings []string
}
func DiagsToErrorsAndWarnings(errPrefix string, diags hcl.Diagnostics) *ErrorAndWarnings {
return NewErrorsAndWarning(
plugin.DiagsToError(errPrefix, diags),
plugin.DiagsToWarnings(diags)...,
)
}
func NewErrorsAndWarning(err error, warnings ...string) *ErrorAndWarnings {
return &ErrorAndWarnings{
Error: err, Warnings: warnings,
}
}
func (r *ErrorAndWarnings) WrapErrorWithMessage(msg string) *ErrorAndWarnings {
if r.Error != nil {
r.Error = sperr.WrapWithMessage(r.Error, msg)
}
return r
}
func (r *ErrorAndWarnings) AddWarning(warnings ...string) {
r.Warnings = append(r.Warnings, warnings...)
}
func (r *ErrorAndWarnings) ShowWarnings() {
for _, w := range r.Warnings {
error_helpers.ShowWarning(w)
}
}
func (r *ErrorAndWarnings) GetError() error {
if r == nil {
return nil
}
return r.Error
}