當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errored.New函數代碼示例

本文整理匯總了Golang中github.com/contiv/errored.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: handleForceRemoveLock

func (d *DaemonConfig) handleForceRemoveLock(req *config.VolumeRequest, vc *config.Volume, locks []config.UseLocker) error {
	exists, err := control.ExistsVolume(vc, d.Global.Timeout)
	if err != nil && err != errors.NoActionTaken {
		return errors.RemoveVolume.Combine(errored.New(vc.String())).Combine(err)
	}

	if err == errors.NoActionTaken {
		if err := d.completeRemove(req, vc); err != nil {
			return err
		}

		d.removeVolumeUse(locks[0], vc)
	}

	if err != nil {
		return errors.RemoveVolume.Combine(errored.New(vc.String())).Combine(err)
	}

	if !exists {
		d.removeVolume(req, vc)
		return errors.RemoveVolume.Combine(errored.New(vc.String())).Combine(errors.NotExists)
	}

	err = d.completeRemove(req, vc)
	if err != nil {
		return errors.RemoveVolume.Combine(errored.New(vc.String())).Combine(errors.NotExists)
	}

	d.removeVolumeUse(locks[0], vc)
	return nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:31,代碼來源:daemon.go

示例2: SplitName

// SplitName splits a docker volume name from policy/name safely.
func SplitName(name string) (string, string, error) {
	if strings.Count(name, "/") > 1 {
		return "", "", errors.InvalidVolume.Combine(errored.New(name))
	}

	parts := strings.SplitN(name, "/", 2)
	if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
		return "", "", errors.InvalidVolume.Combine(errored.New(name))
	}

	return parts[0], parts[1], nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:13,代碼來源:utils.go

示例3: combineErrors

// Combines array of errors into a single error
func combineErrors(resultErrors []gojson.ResultError) error {
	var errors []string
	for _, err := range resultErrors {
		errors = append(errors, fmt.Sprintf("%s\n", err))
	}
	return errored.New(strings.Join(errors, "\n"))
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:8,代碼來源:validation.go

示例4: CopySnapshot

// CopySnapshot copies a snapshot into a new volume. Takes a DriverOptions,
// snap and volume name (string). Returns error on failure.
func (c *Driver) CopySnapshot(do storage.DriverOptions, snapName, newName string) error {
	intOrigName, err := c.internalName(do.Volume.Name)
	if err != nil {
		return err
	}

	intNewName, err := c.internalName(newName)
	if err != nil {
		return err
	}

	poolName := do.Volume.Params["pool"]

	list, err := c.List(storage.ListOptions{Params: storage.Params{"pool": poolName}})
	for _, vol := range list {
		if intNewName == vol.Name {
			return errored.Errorf("Volume %q already exists", vol.Name)
		}
	}

	errChan := make(chan error, 1)

	cmd := exec.Command("rbd", "snap", "protect", mkpool(poolName, intOrigName), "--snap", snapName)
	er, err := runWithTimeout(cmd, do.Timeout)

	// EBUSY indicates that the snapshot is already protected.
	if err != nil && er.ExitStatus != 0 && er.ExitStatus != int(unix.EBUSY) {
		if er.ExitStatus == int(unix.EEXIST) {
			err = errored.Errorf("Volume %q or snapshot name %q already exists. Snapshots cannot share the same name as the target volume.", do.Volume.Name, snapName).Combine(errors.Exists).Combine(errors.SnapshotProtect)
		}
		errChan <- err
		return err
	}

	defer c.cleanupCopy(snapName, newName, do, errChan)

	cmd = exec.Command("rbd", "clone", mkpool(poolName, intOrigName), mkpool(poolName, intNewName), "--snap", snapName)
	er, err = runWithTimeout(cmd, do.Timeout)
	if err != nil && er.ExitStatus == 0 {
		var err2 *errored.Error
		var ok bool

		err2, ok = err.(*errored.Error)
		if !ok {
			err2 = errored.New(err.Error())
		}
		errChan <- err2.Combine(errors.SnapshotCopy)
		return err2
	}

	if er.ExitStatus != 0 {
		newerr := errored.Errorf("Cloning snapshot to volume (volume %q, snapshot %q): %v", intOrigName, snapName, err).Combine(errors.SnapshotCopy).Combine(errors.SnapshotProtect)
		if er.ExitStatus != int(unix.EEXIST) {
			errChan <- newerr
		}
		return err
	}

	return nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:62,代碼來源:ceph.go

示例5: completeRemove

func (d *DaemonConfig) completeRemove(req *config.VolumeRequest, vc *config.Volume) error {
	if err := control.RemoveVolume(vc, d.Global.Timeout); err != nil && err != errors.NoActionTaken {
		logrus.Warn(errors.RemoveImage.Combine(errored.New(vc.String())).Combine(err))
	}

	return d.removeVolume(req, vc)
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:7,代碼來源:daemon.go

示例6: removeVolume

func (d *DaemonConfig) removeVolume(req *config.VolumeRequest, vc *config.Volume) error {
	if err := d.Config.RemoveVolume(req.Policy, req.Name); err != nil {
		return errors.ClearVolume.Combine(errored.New(vc.String())).Combine(err)
	}

	return nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:7,代碼來源:daemon.go

示例7: handleListAll

func (d *DaemonConfig) handleListAll(w http.ResponseWriter, r *http.Request) {
	vols, err := d.Config.ListAllVolumes()
	if err != nil {
		api.RESTHTTPError(w, errors.ListVolume.Combine(err))
		return
	}

	response := []*config.Volume{}
	for _, vol := range vols {
		parts := strings.SplitN(vol, "/", 2)
		if len(parts) != 2 {
			api.RESTHTTPError(w, errors.InvalidVolume.Combine(errored.New(vol)))
			return
		}
		// FIXME make this take a single string and not a split one
		volConfig, err := d.Config.GetVolume(parts[0], parts[1])
		if err != nil {
			api.RESTHTTPError(w, errors.ListVolume.Combine(err))
			return
		}

		response = append(response, volConfig)
	}

	content, err := json.Marshal(response)
	if err != nil {
		api.RESTHTTPError(w, errors.ListVolume.Combine(err))
		return
	}

	w.Write(content)
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:32,代碼來源:daemon.go

示例8: CombineError

// CombineError is a simplication of errored.Combine
func CombineError(err error, format string, args ...interface{}) error {
	if erd, ok := err.(*errored.Error); ok {
		erd.Combine(errored.Errorf(format, args...))
	}

	return errored.New(err.Error()).Combine(errored.Errorf(format, args...))
}
開發者ID:unclejack,項目名稱:volplugin,代碼行數:8,代碼來源:utils.go

示例9: Validate

func (t *testEntity) Validate() error {
	if t.FailsValidation {
		return errored.New("failed validation")
	}

	return nil
}
開發者ID:unclejack,項目名稱:volplugin,代碼行數:7,代碼來源:entity_test.go

示例10: Path

// Path provides the path to this volumes data store.
func (v *Volume) Path() (string, error) {
	if v.PolicyName == "" || v.VolumeName == "" {
		return "", errors.InvalidVolume.Combine(errored.New("Volume or policy name is missing"))
	}

	return strings.Join([]string{v.Prefix(), v.PolicyName, v.VolumeName}, "/"), nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:8,代碼來源:volume.go

示例11: Validate

// Validate does nothing on use locks.
func (m *Use) Validate() error {
	parts := strings.Split(m.Volume, "/")
	if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
		return errors.InvalidVolume.Combine(errored.New(m.Volume))
	}

	return nil
}
開發者ID:unclejack,項目名稱:volplugin,代碼行數:9,代碼來源:use.go

示例12: handleCreate

func (d *DaemonConfig) handleCreate(w http.ResponseWriter, r *http.Request) {
	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		api.RESTHTTPError(w, errors.ReadBody.Combine(err))
		return
	}

	req := &config.VolumeRequest{}

	if err := json.Unmarshal(content, req); err != nil {
		api.RESTHTTPError(w, errors.UnmarshalRequest.Combine(err))
		return
	}

	if req.Policy == "" {
		api.RESTHTTPError(w, errors.GetPolicy.Combine(errored.Errorf("policy was blank")))
		return
	}

	if req.Name == "" {
		api.RESTHTTPError(w, errors.GetVolume.Combine(errored.Errorf("volume was blank")))
		return
	}

	hostname, err := os.Hostname()
	if err != nil {
		api.RESTHTTPError(w, errors.GetHostname.Combine(err))
		return
	}

	policy, err := d.Config.GetPolicy(req.Policy)
	if err != nil {
		api.RESTHTTPError(w, errors.GetPolicy.Combine(errored.New(req.Policy).Combine(err)))
		return
	}

	uc := &config.UseMount{
		Volume:   strings.Join([]string{req.Policy, req.Name}, "/"),
		Reason:   lock.ReasonCreate,
		Hostname: hostname,
	}

	snapUC := &config.UseSnapshot{
		Volume: strings.Join([]string{req.Policy, req.Name}, "/"),
		Reason: lock.ReasonCreate,
	}

	err = lock.NewDriver(d.Config).ExecuteWithMultiUseLock(
		[]config.UseLocker{uc, snapUC},
		d.Global.Timeout,
		d.createVolume(w, req, policy),
	)
	if err != nil && err != errors.Exists {
		api.RESTHTTPError(w, errors.CreateVolume.Combine(err))
		return
	}
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:57,代碼來源:daemon.go

示例13: unmarshalRequest

func unmarshalRequest(r *http.Request) (*config.VolumeRequest, error) {
	cfg := &config.VolumeRequest{}

	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return cfg, err
	}

	if err := json.Unmarshal(content, cfg); err != nil {
		return cfg, err
	}

	if cfg.Policy == "" {
		return cfg, errored.New("Policy was blank")
	}

	if cfg.Name == "" {
		return cfg, errored.New("volume was blank")
	}

	return cfg, nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:22,代碼來源:daemon.go

示例14: SetKey

// SetKey implements the SetKey entity interface.
func (p *Policy) SetKey(key string) error {
	suffix := strings.Trim(strings.TrimPrefix(key, rootPolicy), "/")
	if strings.Contains(suffix, "/") {
		return errors.InvalidDBPath.Combine(errored.Errorf("Policy name %q contains invalid characters", suffix))
	}

	if suffix == "" {
		return errors.InvalidDBPath.Combine(errored.New("Policy name is empty"))
	}

	p.Name = suffix
	return nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:14,代碼來源:policy.go

示例15: watchStopPath

// WatchStopPath stops a watch given a path to stop the watch on.
func (c *Client) watchStopPath(path string) error {
	c.watcherMutex.Lock()
	defer c.watcherMutex.Unlock()

	stopChan, ok := c.watchers[path]
	if !ok {
		return errors.InvalidDBPath.Combine(errored.New("missing key during watch"))
	}

	close(stopChan)
	delete(c.watchers, path)

	return nil
}
開發者ID:contiv,項目名稱:volplugin,代碼行數:15,代碼來源:client.go


注:本文中的github.com/contiv/errored.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。