forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
45 lines (34 loc) · 750 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
34
35
36
37
38
39
40
41
42
43
44
45
package provider
import (
"fmt"
"github.com/evcc-io/evcc/util"
)
type errorProvider struct {
err error
}
func init() {
registry.Add("error", NewErrorFromConfig)
}
// NewErrorFromConfig creates error provider
func NewErrorFromConfig(other map[string]interface{}) (Provider, error) {
var cc struct {
Error string
}
if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}
err := knownErrors([]byte(cc.Error))
if err == nil {
return nil, fmt.Errorf("unknown error: %s", cc.Error)
}
o := &errorProvider{
err: err,
}
return o, nil
}
var _ SetIntProvider = (*errorProvider)(nil)
func (o *errorProvider) IntSetter(param string) (func(int64) error, error) {
return func(int64) error {
return o.err
}, nil
}