mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
chore: return error when override fails
This commit is contained in:
parent
3f2e93e156
commit
634c8065f1
|
@ -589,7 +589,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
|||
// apply overrides
|
||||
err := ApplyOverride(rawCfg, rawCfg.Override)
|
||||
if err != nil {
|
||||
log.Errorln("Error when applying overrides: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
general, err := parseGeneral(rawCfg)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
|
@ -55,7 +57,7 @@ func ApplyOverride(rawCfg *RawConfig, overrides []RawOverride) error {
|
|||
overrideContent, err := yaml.Marshal(override.Content)
|
||||
if err != nil {
|
||||
log.Errorln("Error when applying override #%v: %v", id, err)
|
||||
continue
|
||||
return err
|
||||
}
|
||||
|
||||
// unmarshal override content into rawConfig, with custom list merge strategy
|
||||
|
@ -69,11 +71,13 @@ func ApplyOverride(rawCfg *RawConfig, overrides []RawOverride) error {
|
|||
case Override, Default:
|
||||
err = yaml.Unmarshal(overrideContent, rawCfg)
|
||||
default:
|
||||
log.Errorln("Bad list strategy in override #%v: %v", id, override.ListStrategy)
|
||||
err = errors.New(fmt.Sprintf("Bad list strategy in override #%v: %v", id, override.ListStrategy))
|
||||
log.Errorln(err.Error())
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorln("Error when applying override #%v: %v", id, err)
|
||||
continue
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -245,4 +246,26 @@ override:
|
|||
assert.Contains(t, cfg.Providers, "provider3")
|
||||
assert.Equal(t, "https://www.google.com", cfg.Providers["provider3"].HealthCheckURL())
|
||||
})
|
||||
|
||||
t.Run("bad_override", func(t *testing.T) {
|
||||
config_file := `
|
||||
mixed-port: 7890
|
||||
ipv6: true
|
||||
log-level: debug
|
||||
allow-lan: false
|
||||
unified-delay: false
|
||||
tcp-concurrent: true
|
||||
external-controller: 127.0.0.1:9090
|
||||
default-nameserver:
|
||||
- "223.5.5.5"
|
||||
override:
|
||||
- list-strategy: 12wlfiu3o
|
||||
content:
|
||||
external-controller: 0.0.0.0:9090
|
||||
allow-lan: true`
|
||||
rawCfg, err := UnmarshalRawConfig([]byte(config_file))
|
||||
assert.NoError(t, err)
|
||||
_, err = ParseRawConfig(rawCfg)
|
||||
assert.True(t, strings.HasPrefix(err.Error(), "Bad list strategy in override #0:"))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user