// WrapRetryableError takes an error, and given a set of retryable error regexes, returns
// a suitable error type, either a standard error or a retryable error
777008
func WrapRetryableError(err error, errorList []*regexp.Regexp, errorCreator ErrorCreator) error {
	if err == nil {
		return nil
	}
	for _, errorRegex := range errorList {
		if errorRegex.MatchString(err.Error()) {
			return errorCreator(err)
		}
	}
	return err
}
107612
func IsRetryableError(err error) bool {
	if err == nil {
		return false
	}

	if ErrRetryable.Equal(err) ||
		ErrLockConflict.Equal(err) ||
		ErrConditionNotMatch.Equal(err) ||
		// TiKV exception message will tell you if you should retry or not
		strings.Contains(err.Error(), "try again later") {
		return true
	}

	return false
}
677965
func (e *Error) WrappedErrors() []error {
	if e == nil {
		return nil
	}

	result := make([]error, len(e.Errors))
	for i, e := range e.Errors {
		result[i] = errors.New(e)
	}

	return result
}
962485
func Wrap(err error, message string) error {
	if err == nil {
		return nil
	}
	return &wrapping{
		cause: err,
		msg:   message,
		stack: callers(),
	}
}
1298309
func RetryIsErr(fn func(error) bool) RetryFn {
	return func(attempt Attempt) bool {
		return fn(attempt.Error)
	}
}
320393
func Unwrap(err error) error {
	for {
		wrap, ok := err.(Wrapped)
		if !ok {
			return err
		}

		inner := wrap.InnerError()
		if inner == nil {
			break
		}
		err = inner
	}
	return err
}
418644
func Wrapf(err error, format string, args ...interface{}) error {
	return errs.Wrapf(err, format, args...)
}
294150
func (p *pageState) wrapError(err error) error {

	var filename string
	if !p.File().IsZero() {
		filename = p.File().Filename()
	}

	err, _ = herrors.WithFileContextForFile(
		err,
		filename,
		filename,
		p.s.SourceSpec.Fs.Source,
		herrors.SimpleLineMatcher)

	return err
}
1158264
func IsRetryableError(err error) bool {
	if err == io.EOF {
		return true
	}
	if _, ok := err.(*FailedToOpenFileError); ok {
		return true
	}

	return false
}
884083
func (s *Wrapper) GetReadError() error {
	s.RLock()
	defer s.RUnlock()
	return s.readErr
}
857059
func RetryOnError(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
	if err == nil {
		return false, nil
	}

	e := errors.Parse(err.Error())
	if e == nil {
		return false, nil
	}

	switch e.Code {
	// retry on timeout or internal server error
	case 408, 500:
		return true, nil
	default:
		return false, nil
	}
}
57412
func (s *FailedItemDetails) SetRetryable(v bool) *FailedItemDetails {
	s.Retryable = &v
	return s
}
295699
func (s *TrainingJobStatusCounters) SetRetryableError(v int64) *TrainingJobStatusCounters {
	s.RetryableError = &v
	return s
}
987954
func Unwrap(err error) error {
	if terr, ok := err.(Error); ok {
		return terr.OrigError()
	}
	return err
}
191260
func WrapErrf(cause error, format string, args ...interface{}) error {
	if cause == nil {
		return nil
	}

	err := cause.(*Err)
	return &Err{
		Code:    err.Code,
		Message: fmt.Sprintf(format, args...),
		Cause:   err,
	}
}
322908
func IsRetryableNetworkError(err error) bool {
	if err == nil {
		return false
	}
	// get original error if it was wrapped
	err = argoerrs.Cause(err)
	errStr := err.Error()

	switch err.(type) {
	case net.Error:
		switch err.(type) {
		case *net.DNSError, *net.OpError, net.UnknownNetworkError:
			return true
		case *url.Error:
			// For a URL error, where it replies back "connection closed"
			// retry again.
			if strings.Contains(errStr, "Connection closed by foreign host") {
				return true
			}
		default:
			if strings.Contains(errStr, "net/http: TLS handshake timeout") {
				// If error is - tlsHandshakeTimeoutError, retry.
				return true
			} else if strings.Contains(errStr, "i/o timeout") {
				// If error is - tcp timeoutError, retry.
				return true
			} else if strings.Contains(errStr, "connection timed out") {
				// If err is a net.Dial timeout, retry.
				return true
			}
		}
	}
	return false
}
1166717
func newWrappedError(err error, message string) *wrappedError {
	if err == nil {
		err = errors.New("Error")
	}

	var errWithCause errorWithCause

	if len(message) > 0 {
		errWithCause = errors.Wrap(err, message).(errorWithCause)
	} else if ewc, ok := err.(errorWithCause); ok {
		errWithCause = ewc
	} else {
		errWithCause = errors.Wrap(err, "LFS").(errorWithCause)
	}

	return &wrappedError{
		context:        make(map[string]interface{}),
		errorWithCause: errWithCause,
	}
}