Add more context to configuration errors to simplify diagnosis
This commit is contained in:
parent
a0bdee5c96
commit
8eca79a675
4 changed files with 30 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/andig/evcc/api"
|
"github.com/andig/evcc/api"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type apiFunction string
|
type apiFunction string
|
||||||
|
|
@ -38,5 +39,9 @@ func NewFromConfig(typ string, other map[string]interface{}) (charger api.Charge
|
||||||
return nil, fmt.Errorf("invalid charger type: %s", typ)
|
return nil, fmt.Errorf("invalid charger type: %s", typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("cannot create %s charger", typ))
|
||||||
|
}
|
||||||
|
|
||||||
return charger, err
|
return charger, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,11 @@ func (cp *ConfigProvider) configureMeters(conf config) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FATAL.Fatal(err)
|
log.FATAL.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, exists := cp.meters[cc.Name]; exists {
|
||||||
|
log.FATAL.Fatalf("duplicate meter name: %s already defined and must be unique", cc.Name)
|
||||||
|
}
|
||||||
|
|
||||||
cp.meters[cc.Name] = m
|
cp.meters[cc.Name] = m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,6 +106,11 @@ func (cp *ConfigProvider) configureChargers(conf config) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FATAL.Fatal(err)
|
log.FATAL.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, exists := cp.chargers[cc.Name]; exists {
|
||||||
|
log.FATAL.Fatalf("duplicate charger name: %s already defined and must be unique", cc.Name)
|
||||||
|
}
|
||||||
|
|
||||||
cp.chargers[cc.Name] = c
|
cp.chargers[cc.Name] = c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,6 +122,11 @@ func (cp *ConfigProvider) configureVehicles(conf config) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FATAL.Fatal(err)
|
log.FATAL.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, exists := cp.vehicles[cc.Name]; exists {
|
||||||
|
log.FATAL.Fatalf("duplicate vehicle name: %s already defined and must be unique", cc.Name)
|
||||||
|
}
|
||||||
|
|
||||||
cp.vehicles[cc.Name] = v
|
cp.vehicles[cc.Name] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/andig/evcc/api"
|
"github.com/andig/evcc/api"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewFromConfig creates meter from configuration
|
// NewFromConfig creates meter from configuration
|
||||||
|
|
@ -22,5 +23,9 @@ func NewFromConfig(typ string, other map[string]interface{}) (meter api.Meter, e
|
||||||
err = fmt.Errorf("invalid meter type: %s", typ)
|
err = fmt.Errorf("invalid meter type: %s", typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("cannot create %s meter", typ))
|
||||||
|
}
|
||||||
|
|
||||||
return meter, err
|
return meter, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/andig/evcc/api"
|
"github.com/andig/evcc/api"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewFromConfig creates vehicle from configuration
|
// NewFromConfig creates vehicle from configuration
|
||||||
|
|
@ -28,5 +29,9 @@ func NewFromConfig(typ string, other map[string]interface{}) (v api.Vehicle, err
|
||||||
err = fmt.Errorf("invalid vehicle type: %s", typ)
|
err = fmt.Errorf("invalid vehicle type: %s", typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("cannot create %s vehicle", typ))
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue