INNER CODE UNIT · Go
formatErrorString
umputun/spot · cmd/spot/main.go:585
func formatErrorString(input string) string {
headerRe := regexp.MustCompile(`(.*: \d+ error\(s\) occurred:)`)
headerMatch := headerRe.FindStringSubmatch(input)
if len(headerMatch) == 0 {
return input
}
errorsRe := regexp.MustCompile(`\[\d+] {([^}]+)}`)
errorsMatches := errorsRe.FindAllStringSubmatch(input, -1)
formattedErrors := make([]string, 0, len(errorsMatches))
for _, match := range errorsMatches {
formattedErrors = append(formattedErrors, strings.TrimSpace(match[1]))
}
var formattedString strings.Builder
formattedString.WriteString(strings.TrimSpace(headerMatch[1]))