// ErrChanReserveTooLarge returns an error indicating that the chan reserve the
// remote is requiring, is too large to be accepted.
504463
func ErrChanReserveTooLarge(reserve,
	maxReserve btcutil.Amount) ReservationError {
	return ReservationError{
		fmt.Errorf("Channel reserve is too large: %v sat, max "+
			"is %v sat", int64(reserve), int64(maxReserve)),
	}
}
544119
func (a *AbuseRateLimitError) GetRetryAfter() time.Duration {
	if a == nil || a.RetryAfter == nil {
		return 0
	}
	return *a.RetryAfter
}
324553
func (h *HttpClient) GetRetry(rawurl string) ([]byte, error) {
	if rawurl == "" {
		return nil, ErrInvalid{errors.New("URL is empty. Skipping.")}
	}

	url, err := neturl.Parse(rawurl)
	if err != nil {
		return nil, ErrInvalid{err}
	}

	// Unfortunately, url.Parse is too generic to throw errors if a URL does not
	// have a valid HTTP scheme. So, we have to do this extra validation
	if !strings.HasPrefix(url.Scheme, "http") {
		return nil, ErrInvalid{fmt.Errorf("URL %s does not have a valid HTTP scheme. Skipping.", rawurl)}
	}

	dataURL := url.String()

	duration := h.InitialBackoff
	for retry := 1; retry <= h.MaxRetries; retry++ {
		log.Printf("Fetching data from %s. Attempt #%d", dataURL, retry)

		data, err := h.Get(dataURL)
		switch err.(type) {
		case ErrNetwork:
			log.Printf(err.Error())
		case ErrServer:
			log.Printf(err.Error())
		case ErrNotFound:
			return data, err
		default:
			return data, err
		}

		duration = ExpBackoff(duration, h.MaxBackoff)
		log.Printf("Sleeping for %v...", duration)
		time.Sleep(duration)
	}

	return nil, ErrTimeout{fmt.Errorf("Unable to fetch data. Maximum retries reached: %d", h.MaxRetries)}
}
1014639
func (s *Queue) SetReservationPlan(v *ReservationPlan) *Queue {
	s.ReservationPlan = v
	return s
}
553256
func ValidateRepoURL(repoURL string) error {
	_, _, err := ParseRepoURL(repoURL)
	return err
}
440975
func (r *Resource) ReservationRole() string {
	// if using reservation refinement, return the role of the last refinement
	rs := r.GetReservations()
	if x := len(rs); x > 0 {
		return rs[x-1].GetRole()
	}
	// if using the old reservation API, role is a first class field of Resource
	// (and it's never stored in Resource.Reservation).
	return r.GetRole()
}
639
func (r *retryCounter) CanRetry(oid string) (int, bool) {
	count := r.CountFor(oid)
	return count, count < r.MaxRetries
}
959682
func ErrorHandler(cb ErrHandler) Option {
	return func(o *Options) error {
		o.AsyncErrorCB = cb
		return nil
	}
}
527550
func reserveImage(tokenID string, imageEndpoint string, imageMetadata ImageMetadata, imageApiVersion int) (string, error) {
	// Form the URI to create the image
	imagesURI := ""
	if imageVersionEncoded(imageEndpoint) {
		imagesURI = fmt.Sprintf("%simages", imageEndpoint)
	} else {
		imagesURI = fmt.Sprintf("%sv%d/images", imageEndpoint, imageApiVersion)
	}

	// Prepare the request to create the image
	var createReq *http.Request
	var err error
	if imageApiVersion == 1 {
		createReq, err = http.NewRequest("POST", imagesURI, nil)
	} else {
		imageStr, imgErr := json.Marshal(imageMetadata)
		if imgErr != nil {
			return "", imgErr
		}

		createReq, err = http.NewRequest("POST", imagesURI, bytes.NewBuffer(imageStr))
	}
	if err != nil {
		return "", err
	}

	createReq.Header.Add("X-Auth-Token", tokenID)
	if imageApiVersion == 1 {
		createReq.Header.Add("Content-Type", "application/octet-stream")
		createReq.Header.Add("X-Image-Meta-Name", imageMetadata.Name)
		createReq.Header.Add("X-Image-Meta-container_format", imageMetadata.ContainerFormat)
		createReq.Header.Add("X-Image-Meta-disk_format", imageMetadata.DiskFormat)
		createReq.Header.Add("X-Image-Meta-min_disk", strconv.Itoa(imageMetadata.MinDisk))
		createReq.Header.Add("X-Image-Meta-min_ram", strconv.Itoa(imageMetadata.MinRAM))
	} else {
		createReq.Header.Add("Content-Type", "application/json")
	}

	// Send the request to create the image
	httpClient := &http.Client{}
	resp, err := httpClient.Do(createReq)
	if err != nil {
		return "", fmt.Errorf("failed to send a image reserve request")
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode != 201 {
		return "", fmt.Errorf("reserve image request returned bad response, %s", string(body))
	}

	// Parse the result to see if image is created
	var dat map[string]interface{}
	if err := json.Unmarshal(body, &dat); err != nil {
		return "", err
	}

	if imageApiVersion == 1 {
		dat = dat["image"].(map[string]interface{})
	}

	if dat["status"] != imageQueued {
		return "", fmt.Errorf("image has never been created")
	}

	// Retrieve the image ID from http response block
	idFromResponse := dat["id"]
	switch idFromResponse.(type) {
	case string:
		return idFromResponse.(string), nil
	default:
		return "", fmt.Errorf("unable to parse the upload image response")
	}
}
966240
func (m *qosContainerManagerImpl) retrySetMemoryReserve(configs map[v1.PodQOSClass]*CgroupConfig, percentReserve int64) {
	// Unreclaimable memory usage may already exceeded the desired limit
	// Attempt to set the limit near the current usage to put pressure
	// on the cgroup and prevent further growth.
	for qos, config := range configs {
		stats, err := m.cgroupManager.GetResourceStats(config.Name)
		if err != nil {
			klog.V(2).Infof("[Container Manager] %v", err)
			return
		}
		usage := stats.MemoryStats.Usage

		// Because there is no good way to determine of the original Update()
		// on the memory resource was successful, we determine failure of the
		// first attempt by checking if the usage is above the limit we attempt
		// to set.  If it is, we assume the first attempt to set the limit failed
		// and try again setting the limit to the usage.  Otherwise we leave
		// the CgroupConfig as is.
		if configs[qos].ResourceParameters.Memory != nil && usage > *configs[qos].ResourceParameters.Memory {
			configs[qos].ResourceParameters.Memory = &usage
		}
	}
}
1187159
func errRecover(errp *error) {
	e := recover()
	if e != nil {
		switch err := e.(type) {
		case runtime.Error:
			panic(e)
		case error:
			*errp = err
		default:
			panic(e)
		}
	}
}
87016
func (s *state) errRecover(errp *error) {
	if e := recover(); e != nil {
		switch e := e.(type) {
		case runtime.Error:
			*errp = s.errFromNode("%s: %v\n%v", s.callAnnotation(), e, string(debug.Stack()))
		default:
			*errp = s.errFromNode("%s: %v", s.callAnnotation(), e)
		}
	}
}
633269
func (c *ContainerServer) ReserveContainerName(id, name string) (string, error) {
	if err := c.ctrNameIndex.Reserve(name, id); err != nil {
		err = fmt.Errorf("error reserving ctr name %s for id %s", name, id)
		logrus.Warn(err)
		return "", err
	}
	return name, nil
}
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
}
328593
func ErrCsvDelayTooLarge(remoteDelay, maxDelay uint16) ReservationError {
	return ReservationError{
		fmt.Errorf("CSV delay too large: %v, max is %v",
			remoteDelay, maxDelay),
	}
}
230612
func (win *Window) LayoutReserveRowScaled(height int, num int) {
	win.layout.ReservedHeight += height*num + win.style().Spacing.Y*num
}
749090
func (c *EndpointConfig) loadOrdererPeerTLSConfig(configEntity *endpointConfigEntity) error {

	//Orderers Config
	for orderer, ordererConfig := range configEntity.Orderers {
		//resolve paths
		ordererConfig.TLSCACerts.Path = pathvar.Subst(ordererConfig.TLSCACerts.Path)
		//pre load key and cert bytes
		err := ordererConfig.TLSCACerts.LoadBytes()
		if err != nil {
			return errors.WithMessage(err, "failed to load orderer cert")
		}
		configEntity.Orderers[orderer] = ordererConfig
	}

	//Peer Config
	for peer, peerConfig := range configEntity.Peers {
		//resolve paths
		peerConfig.TLSCACerts.Path = pathvar.Subst(peerConfig.TLSCACerts.Path)
		//pre load key and cert bytes
		err := peerConfig.TLSCACerts.LoadBytes()
		if err != nil {
			return errors.WithMessage(err, "failed to load peer cert")
		}
		configEntity.Peers[peer] = peerConfig
	}

	return nil
}