当前位置: 首页>>代码示例>>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;未经允许,请勿转载。