소스 검색

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.
Shelikhoo 4 년 전
부모
커밋
40140c2977
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      config.go

+ 4 - 1
config.go

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