diff --git a/cmd/config.go b/cmd/config.go index 2108b42d3..d2a4d1a8f 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -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) } diff --git a/util/decoder.go b/util/decoder.go index b9155a04b..068fb2c22 100644 --- a/util/decoder.go +++ b/util/decoder.go @@ -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 +}