-
Notifications
You must be signed in to change notification settings - Fork 14
/
ignore_error_config.go
56 lines (49 loc) · 1.91 KB
/
ignore_error_config.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
51
52
53
54
55
56
package plugin
import (
"fmt"
"log"
"strings"
"github.com/turbot/go-kit/helpers"
)
type IgnoreConfig struct {
ShouldIgnoreErrorFunc ErrorPredicateWithContext
// deprecated, used ShouldIgnoreErrorFunc
ShouldIgnoreError ErrorPredicate
}
func (c *IgnoreConfig) String() interface{} {
var s strings.Builder
if c.ShouldIgnoreError != nil {
s.WriteString(fmt.Sprintf("ShouldIgnoreError: %s\n", helpers.GetFunctionName(c.ShouldIgnoreError)))
}
if c.ShouldIgnoreErrorFunc != nil {
s.WriteString(fmt.Sprintf("ShouldIgnoreErrorFunc: %s\n", helpers.GetFunctionName(c.ShouldIgnoreErrorFunc)))
}
return s.String()
}
func (c *IgnoreConfig) Validate(table *Table) []string {
if c.ShouldIgnoreError != nil && c.ShouldIgnoreErrorFunc != nil {
log.Printf("[TRACE] IgnoreConfig validate failed - both ShouldIgnoreError and ShouldIgnoreErrorFunc are defined")
return []string{fmt.Sprintf("table '%s' both ShouldIgnoreError and ShouldIgnoreErrorFunc are defined", table.Name)}
}
return nil
}
func (c *IgnoreConfig) DefaultTo(other *IgnoreConfig) {
// if not other provided, nothing to do
if other == nil {
return
}
// if either ShouldIgnoreError or ShouldIgnoreErrorFunc are set, do not default to other
if c.ShouldIgnoreError != nil || c.ShouldIgnoreErrorFunc != nil {
log.Printf("[TRACE] IgnoreConfig DefaultTo: config defines a should ignore function so not defaulting to base")
return
}
// legacy func
if c.ShouldIgnoreError == nil && other.ShouldIgnoreError != nil {
log.Printf("[TRACE] IgnoreConfig DefaultTo: using base ShouldIgnoreError: %s", helpers.GetFunctionName(other.ShouldIgnoreError))
c.ShouldIgnoreError = other.ShouldIgnoreError
}
if c.ShouldIgnoreErrorFunc == nil && other.ShouldIgnoreErrorFunc != nil {
log.Printf("[TRACE] IgnoreConfig DefaultTo: using base ShouldIgnoreErrorFunc: %s", helpers.GetFunctionName(other.ShouldIgnoreErrorFunc))
c.ShouldIgnoreErrorFunc = other.ShouldIgnoreErrorFunc
}
}