1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -05:00

better error reason reporting for auto config format

Without this change, the user will not be able to know the detail of error if auto config format detection is used.
This commit is contained in:
Shelikhoo 2021-09-28 18:30:26 +01:00
parent 82e730bb70
commit 40140c2977
No known key found for this signature in database
GPG Key ID: AA7BC347968E7DB1

View File

@ -145,6 +145,7 @@ func loadSingleConfigAutoFormat(input interface{}) (*Config, error) {
return nil, newError("config loader not found for: ", extension).AtWarning()
}
}
var errorReasons strings.Builder
// no extension, try all loaders
for _, f := range configLoaders {
if f.Name[0] == FormatAuto {
@ -153,9 +154,11 @@ func loadSingleConfigAutoFormat(input interface{}) (*Config, error) {
c, err := f.Loader(input)
if err == nil {
return c, nil
} else {
errorReasons.WriteString(fmt.Sprintf("unable to parse as %v:%v;", f.Name[0], err.Error()))
}
}
return nil, newError("tried all loaders but failed for: ", input).AtWarning()
return nil, newError("tried all loaders but failed when attempting to parse: ", input, ";", errorReasons.String()).AtWarning()
}
func getInputCount(input interface{}) int {