Vehicles: fail if vehicle config cannot be decoded (#5724)

This commit is contained in:
andig 2023-01-08 20:06:22 +01:00 • committed by GitHub
parent c18475b050
commit 2515bb14a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -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)
}

View file

@ -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
}