// ErrorTimeFinder unwraps a timestamp annotated error if possible and
// is capable of finding a timestamp in an error that has been
// annotated using pkg/errors.
764686
func ErrorTimeFinder(err error) (time.Time, bool) {
	if err == nil {
		return time.Time{}, false
	}

	if tserr, ok := err.(*timestampError); ok {
		if tserr == nil {
			return time.Time{}, false
		}
		return tserr.time, true
	}

	for {
		if e, ok := err.(errorCauser); ok {
			if tserr, ok := e.(*timestampError); ok {
				if tserr == nil {
					break
				}
				return tserr.time, true
			}
			err = e.Cause()
			continue
		}
		break
	}

	return time.Time{}, false
}
11368
func ErrorIsNotFound(err error) bool {
	_, ok := errors.Cause(err).(*ErrNotFound)
	return ok
}
570557
func getLastChangeTriggerTime(endpoints *v1.Endpoints) time.Time {
	if _, ok := endpoints.Annotations[v1.EndpointsLastChangeTriggerTime]; !ok {
		// It's possible that the Endpoints object won't have the EndpointsLastChangeTriggerTime
		// annotation set. In that case return the 'zero value', which is ignored in the upstream code.
		return time.Time{}
	}
	val, err := time.Parse(time.RFC3339Nano, endpoints.Annotations[v1.EndpointsLastChangeTriggerTime])
	if err != nil {
		klog.Warningf("Error while parsing EndpointsLastChangeTriggerTimeAnnotation: '%s'. Error is %v",
			endpoints.Annotations[v1.EndpointsLastChangeTriggerTime], err)
		// In case of error val = time.Zero, which is ignored in the upstream code.
	}
	return val
}
1052409
func errorOrWarning(err error, ctx context.Context) error {
	sc := ctx.GetSessionVars().StmtCtx
	// TODO: Use better name, such as sc.IsInsert instead of sc.IgnoreTruncate.
	if ctx.GetSessionVars().StrictSQLMode && !sc.IgnoreTruncate {
		return errors.Trace(types.ErrInvalidTimeFormat)
	}
	sc.AppendWarning(err)
	return nil
}
204891
func TimeTrack(start time.Time, name string) {
	elapsed := time.Since(start)
	log.Printf("%s took %s", name, elapsed)
}
556032
func NewTimeformatLogger(out io.Writer, timeFormat string) Logger {
	return &standardLogger{
		out:        out,
		timeFormat: timeFormat,
	}
}
339179
func (o *pdOracle) GetTimestamp(ctx context.Context) (uint64, error) {
	ts, err := o.getTimestamp(ctx)
	if err != nil {
		return 0, errors.Trace(err)
	}
	o.setLastTS(ts)
	return ts, nil
}
670159
func UnwrapError(err error) (*Error, bool) {
	switch e := err.(type) {
	case *wrappedError:
		return e.err, true
	default:
		return nil, false
	}
}
177446
func (v *Validator) validTimestamp(ts string) bool {
	t, err := stringToTime(ts)
	if err != nil {
		return false
	}
	diff := time.Now().Add(ValidityWindow / 2).Sub(t)
	return diff < ValidityWindow && diff > 0
}
1152824
func IsTimeout(err error) bool {
	if err, ok := err.(net.Error); ok && err.Timeout() {
		return true
	}
	err = getInnerError(err)
	return err == ErrTimeout
}
228345
func (f *DurationFlag) ApplyWithError(set *flag.FlagSet) error {
	f.set = set
	return f.DurationFlag.ApplyWithError(set)
}
579580
func IsTimeoutError(err error) bool {
	switch errType := errors.Cause(err).(type) {
	case TimeoutError:
		return errType.Timeout()
	default:
		return false
	}
}
156972
func FindError(err error, code Code) Code {
	if err == nil {
		return NonError
	}

	if merr, ok := err.(*multierror.Error); ok {
		if merr.ErrorOrNil() == nil {
			return NonError
		}
		for _, e := range merr.Errors {
			if rfcErr, ok := e.(*Error); ok {
				if rfcErr.Code == code {
					return code
				}
			}
		}
	}
	return NonRFCError
}
843076
func checkForEmptyError(err error) error {
	if err != nil {
		return nil
	}
	msg := "attempted to notify Bugsnag without supplying an error. Bugsnag not notified"
	Config.Logger.Printf("ERROR: " + msg)
	return fmt.Errorf(msg)
}
1141744
func ErrorHandler(h utils.ErrorHandler) LBOption {
	return func(s *RoundRobin) error {
		s.errHandler = h
		return nil
	}
}
517486
func Error(t TestingT, err error, msgAndArgs ...interface{}) {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	if assert.Error(t, err, msgAndArgs...) {
		return
	}
	t.FailNow()
}
374930
func toTime(s string) (t time.Time, err error) {
	if s != "" {
		t, err = time.Parse(time.RFC3339, s)
	}

	return
}