// lintErrorStrings examines error strings.
// It complains if they are capitalized or end in punctuation or a newline.
769385
func (f *file) lintErrorStrings() {
	f.walk(func(node ast.Node) bool {
		ce, ok := node.(*ast.CallExpr)
		if !ok {
			return true
		}
		if !isPkgDot(ce.Fun, "errors", "New") && !isPkgDot(ce.Fun, "fmt", "Errorf") {
			return true
		}
		if len(ce.Args) < 1 {
			return true
		}
		str, ok := ce.Args[0].(*ast.BasicLit)
		if !ok || str.Kind != token.STRING {
			return true
		}
		s, _ := strconv.Unquote(str.Value) // can assume well-formed Go
		if s == "" {
			return true
		}
		clean, conf := lintErrorString(s)
		if clean {
			return true
		}

		f.errorf(str, conf, link(styleGuideBase+"#error-strings"), category("errors"),
			"error strings should not be capitalized or end with punctuation or a newline")
		return true
	})
}
1098641
func filterErrors(list []error, fns ...Matcher) []error {
	result := []error{}
	for _, err := range list {
		r := FilterOut(err, fns...)
		if r != nil {
			result = append(result, r)
		}
	}
	return result
}
673244
func CompileStrs(regStrs []string) (*regexp.Regexp, error) {
	if len(regStrs) == 0 {
		return nil, fmt.Errorf("regStrs must be greater than or equal to 1")
	}
	regStr := "(" + strings.Join(regStrs, "|") + ")"
	re, err := regexp.Compile(regStr)
	if err != nil {
		return nil, err
	}
	return re, nil
}
1303352
func (a *Assertion) PanicString(fn func(), str string, msg ...interface{}) *Assertion {
	PanicString(a.t, fn, str, msg...)
	return a
}
82261
func CombineErrors(delimiter string, errs ...error) error {
	var formatStrs = []string{}

	for _, e := range errs {
		if e == nil {
			continue
		}
		formatStrs = append(formatStrs, e.Error())
	}

	return fmt.Errorf(strings.Join(formatStrs, delimiter))
}
799163
func (e *Error) Error() string {
	var ret string
	ret = e.desc + "\n"

	// TODO: use github.com/pkg/errors
	for _, stack := range e.stack {
		ret += fmt.Sprintf("%s [%s %d]\n", stack.fun, stack.file, stack.line)
	}
	return ret
}
1149807
func hlLinesToRanges(startLine int, s string) ([][2]int, error) {
	var ranges [][2]int
	s = strings.TrimSpace(s)

	if s == "" {
		return ranges, nil
	}

	// Variants:
	// 1 2 3 4
	// 1-2 3-4
	// 1-2 3
	// 1 3-4
	// 1    3-4
	fields := strings.Split(s, " ")
	for _, field := range fields {
		field = strings.TrimSpace(field)
		if field == "" {
			continue
		}
		numbers := strings.Split(field, "-")
		var r [2]int
		first, err := strconv.Atoi(numbers[0])
		if err != nil {
			return ranges, err
		}
		first = first + startLine - 1
		r[0] = first
		if len(numbers) > 1 {
			second, err := strconv.Atoi(numbers[1])
			if err != nil {
				return ranges, err
			}
			second = second + startLine - 1
			r[1] = second
		} else {
			r[1] = first
		}

		ranges = append(ranges, r)
	}
	return ranges, nil

}
1087291
func Error(err error) *string {
	if err == nil {
		return nil
	}
	str := err.Error()
	return &str
}
631565
func sortErrors(allErrors map[string][]Error) {
	for _, errors := range allErrors {
		sort.Slice(errors, func(i, j int) bool {
			if errors[i].Line == errors[j].Line {
				return errors[i].Column <= errors[j].Column
			}
			return errors[i].Line < errors[j].Line
		})
	}
}
950267
func (e *Error) Error() string {
	if len(e.Stderr) == 0 {
		return e.ExitError.Error()
	}
	n := bytes.IndexByte(e.Stderr, '\n')
	if n < 0 {
		return string(e.Stderr)
	}
	return string(e.Stderr[:n])
}
1012189
func generateErrString(failedClosers []closer) (errString string) {
	for i, fc := range failedClosers {
		if i == 0 {
			errString = fmt.Sprintf("%s/%s: %s", fc.PKGPath, fc.Name, fc.Err)
			continue
		}
		errString = fmt.Sprintf("%s, %s/%s: %s", errString, fc.PKGPath, fc.Name, fc.Err)
	}

	return errString
}
72832
func Error(format string, args ...interface{}) {
	if len(args) == 0 {
		fmt.Fprintln(ErrorWriter, format)
		return
	}
	fmt.Fprintf(ErrorWriter, format+"\n", args...)
}
2504
func ErrorString(w http.ResponseWriter, status int, code string, err error) {
	Error(w, status, types.NewErrorV1(code, err.Error()))
}
721921
func (e errorList) Error() string {
	msg := ""
	if size := len(e); size > 0 {
		for i := 0; i < size; i++ {
			msg += fmt.Sprintf("%s", e[i].Error())
			// We check the next index to see if it is within the slice.
			// If it is, then we append a newline. We do this, because unit tests
			// could be broken with the additional '\n'.
			if i+1 < size {
				msg += "\n"
			}
		}
	}
	return msg
}
1038510
func fmtError(introMsg string, err error, jsonFlag bool) string {
	renderedTxt := ""
	uiErr := errorToUIErr(err)
	// JSON print
	if jsonFlag {
		// Message text in json should be simple
		if uiErr.detail != "" {
			return uiErr.msg + ": " + uiErr.detail
		}
		return uiErr.msg
	}
	// Pretty print error message
	introMsg += ": "
	if uiErr.msg != "" {
		introMsg += colorBold(uiErr.msg + ".")
	} else {
		introMsg += colorBold(err.Error() + ".")
	}
	renderedTxt += colorRed(introMsg) + "\n"
	// Add action message
	if uiErr.action != "" {
		renderedTxt += "> " + colorBgYellow(colorBlack(uiErr.action+".")) + "\n"
	}
	// Add help
	if uiErr.help != "" {
		renderedTxt += colorBold("HELP:") + "\n"
		renderedTxt += "  " + uiErr.help
	}
	return renderedTxt
}
590531
func (e *Error) Error() string {
	nle := C.GoString(C.nl_geterror(e.errno))
	return fmt.Sprintf("%s: %s", e.msg, strings.ToLower(nle))
}
324375
func (d *Decoder) syntaxError(msg string) error {
	return &SyntaxError{Msg: msg, Line: d.line}
}