Vehicles: fail if vehicle config cannot be decoded (#5724)
This commit is contained in:
parent
c18475b050
commit
2515bb14a8
2 changed files with 24 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -260,8 +261,13 @@ func (cp *ConfigProvider) configureVehicles(conf config) error {
|
|||
g.Go(func() error {
|
||||
v, err := vehicle.NewFromConfig(cc.Type, cc.Other)
|
||||
if err != nil {
|
||||
var ce *util.ConfigError
|
||||
if errors.As(err, &ce) {
|
||||
return fmt.Errorf("cannot create vehicle '%s': %w", cc.Name, err)
|
||||
}
|
||||
|
||||
// wrap non-config vehicle errors to prevent fatals
|
||||
log.ERROR.Printf("creating vehicle %s failed: %v", cc.Name, err)
|
||||
// wrap any created errors to prevent fatals
|
||||
v = wrapper.New(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,5 +21,22 @@ func DecodeOther(other, cc interface{}) error {
|
|||
err = decoder.Decode(other)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = &ConfigError{err}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// ConfigError wraps yaml configuration errors from mapstructure
|
||||
type ConfigError struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *ConfigError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
func (e *ConfigError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue