// NewLogarithmicRetryableError creates a RetryableError which will retry up
// to maxAttempts times, with a sleep pattern defined by a logarithmic curve
330821
func NewLogarithmicRetryableError(err error, maxAttempts int, baseOffset, scale, power float64) RetryableError {
	return &logarithmicRetryableError{err, maxAttempts, baseOffset, scale, power}
}
143174
func (s *LabelCounters) SetFailedNonRetryableError(v int64) *LabelCounters {
	s.FailedNonRetryableError = &v
	return s
}
509979
func WrapRecoverable(msg string, err error) error {
	return &RecoverableError{Err: msg, Recoverable: IsRecoverable(err)}
}
1033979
func ResponseLogAndError(v interface{}) {
	if e, ok := v.(*logrus.Entry); ok {
		e.Error(e.Message)
		oldFormatter := e.Logger.Formatter
		logrus.SetFormatter(&logrus.JSONFormatter{})
		s, err := e.String()
		logrus.SetFormatter(oldFormatter)
		if err != nil {
			ResponseError(err.Error())
			return
		}
		// Cosmetic since " would be escaped
		ResponseError(strings.Replace(s, "\"", "'", -1))
	} else {
		e, isErr := v.(error)
		_, isRuntimeErr := e.(runtime.Error)
		if isErr && !isRuntimeErr {
			logrus.Errorf(fmt.Sprint(e))
			ResponseError(fmt.Sprint(e))
		} else {
			logrus.Errorf("Caught FATAL error: %s", v)
			debug.PrintStack()
			ResponseError("Caught FATAL error: %s", v)
		}
	}
}
72188
func NewCliError(reqType string, hr *gocd.APIResponse, err error) (jerr JSONCliError) {
	data := dataJSONCliError{
		"error": err.Error(),
	}
	if hr != nil {
		data["status"] = hr.HTTP.StatusCode
		data["response-body"] = hr.Body
		data["request-endpoint"] = hr.Request.HTTP.URL.String()

		if hr.HTTP.StatusCode == 404 {
			data["error"] = "Resource not found"
		} else {
			b1, _ := json.Marshal(hr.HTTP.Header)
			b2, _ := json.Marshal(hr.Request.HTTP.Header)
			data["error"] = "An error occurred while retrieving the resource."
			data["response-header"] = string(b1)
			data["request-body"] = hr.Request.Body
			data["request-header"] = string(b2)
		}
	} else {
		data["request"] = reqType
	}
	return JSONCliError{
		data: data,
		resp: hr,
	}
}
870890
func (d *defaulter) logError(format string, err error) {
	if !d.log {
		return
	}
	format += ": %v"
	if len(d.id) > 0 {
		logger.Errorf("(%s) "+format, d.id, err)
	} else {
		logger.Errorf(format, 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
}
594000
func GetOnlyMapEntry(obj map[string]interface{}) (string, interface{}, error) {
	if len(obj) != 1 {
		return "", nil, errutil.InvalidInstanceErrorf(obj, "expected only one entry")
	}

	for key, val := range obj {
		return key, val, nil
	}

	panic("unreachable")
	return "", nil, fmt.Errorf("unreachable")
}
64135
func LogError(task string, err error) error {
	return Log(NewError(task, err))
}
582775
func NewErrRetryTaskLater(msg string, retryIn time.Duration) ErrRetryTaskLater {
	return ErrRetryTaskLater{msg: msg, retryIn: retryIn}
}
844760
func (m *BatchMethodMetrics) ReportRetryableErrors(n int) {
	m.RetryableErrors.Inc(int64(n))
	m.Errors.Inc(int64(n))
}
962472
func IsRetriableError(err error) bool {
	if e, ok := err.(interface {
		RetriableError() bool
	}); ok {
		return e.RetriableError()
	}
	if cause, ok := Cause(err).(*url.Error); ok {
		return cause.Temporary() || cause.Timeout()
	}
	if parent := parentOf(err); parent != nil {
		return IsRetriableError(parent)
	}
	return false
}
457242
func (c *convergence) crashedActualLRPs(logger lager.Logger, now time.Time) {
	logger = logger.Session("crashed-actual-lrps")
	restartCalculator := models.NewDefaultRestartCalculator()

	rows, err := c.selectCrashedLRPs(logger, c.db)
	if err != nil {
		logger.Error("failed-query", err)
		return
	}

	for rows.Next() {
		var index int
		actual := &models.ActualLRP{}

		schedulingInfo, err := c.fetchDesiredLRPSchedulingInfoAndMore(logger, rows, &index, &actual.Since, &actual.CrashCount)
		if err != nil {
			continue
		}

		actual.ActualLRPKey = models.NewActualLRPKey(schedulingInfo.ProcessGuid, int32(index), schedulingInfo.Domain)
		actual.State = models.ActualLRPStateCrashed

		if actual.ShouldRestartCrash(now, restartCalculator) {
			c.unstartedLRPKeys = append(c.unstartedLRPKeys, &models.ActualLRPKeyWithSchedulingInfo{
				Key:            &actual.ActualLRPKey,
				SchedulingInfo: schedulingInfo,
			})
			logger.Info("creating-start-request",
				lager.Data{"reason": "crashed-instance", "process_guid": actual.ProcessGuid, "index": index})
		}
	}

	if rows.Err() != nil {
		logger.Error("failed-getting-next-row", rows.Err())
	}

	return
}
284535
func LogarithmicBatchingPolicy(maxConcurrentInvs, maxBatchSize int, logBase float64) (Func, error) {
	// We use 1.0001 to ensure that operation below returns a value small enough
	// to fit into int and to avoid numerical stability issues resulting from
	// very small values being approximated as 0 and resulting in
	// division-by-zero errors.
	if logBase < 1.0001 {
		return nil, errors.Reason("log_base should be more or equal than 1.0001").Err()
	}

	log := math.Log(logBase)
	return basePolicy(maxConcurrentInvs, maxBatchSize, func(triggers []*internal.Trigger) int {
		return int(math.Max(math.Log(float64(len(triggers)))/log, 1.0))
	})
}
131987
func retryOnError(err error) bool {
	switch err := err.(type) {
	case *os.PathError:
		return retryOnError(err.Err) // unpack the target error
	case syscall.Errno:
		if err == unix.EPERM {
			// EPERM represents an entropy pool exhaustion, a condition under
			// which we backoff and retry.
			return true
		}
	}

	return false
}
1036540
func IfErrAndReturn(l Logger, err error) error {
	if err != nil {
		l.Log(Err, err)
	}
	return err
}
739792
func newMemifError(code int, desc ...string) *MemifError {
	var err *MemifError
	if len(desc) > 0 {
		err = &MemifError{code: code, description: "libmemif: " + desc[0]}
	} else {
		err = &MemifError{code: code, description: "libmemif: " + C.GoString(C.memif_strerror(C.int(code)))}
	}
	errorRegistry[code] = err
	return err
}