当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.NewErr函数代码示例

本文整理汇总了Golang中github.com/juju/errors.NewErr函数的典型用法代码示例。如果您正苦于以下问题:Golang NewErr函数的具体用法?Golang NewErr怎么用?Golang NewErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewErr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: LastLog

func (s *memStorage) LastLog(logID string) (string, error) {
	logData, ok := s.data[logID]
	if !ok {
		err := errors.NewErr("LogData %s not found", logID)
		return "", &err
	}
	sizeOfLog := len(logData)
	if sizeOfLog == 0 {
		return "", errors.New("LogData is empty")
	}
	lastLog := logData[sizeOfLog-1]
	return lastLog, nil
}
开发者ID:lysu,项目名称:go-saga,代码行数:13,代码来源:memory.go

示例2: WrapWithDeserializationError

// WrapWithDeserializationError constructs a new DeserializationError with the
// specified message, and sets the location and returns a new error with the
// full error stack set including the error passed in.
func WrapWithDeserializationError(err error, format string, args ...interface{}) error {
	message := fmt.Sprintf(format, args...)
	// We want the deserialization error message to include the error text of the
	// previous error, but wrap it in the new type.
	derr := &DeserializationError{Err: errors.NewErr(message + ": " + err.Error())}
	derr.SetLocation(1)
	wrapped := errors.Wrap(err, derr)
	// We want the location of the wrapped error to be the caller of this function,
	// not the line above.
	if errType, ok := wrapped.(*errors.Err); ok {
		// We know it is because that is what Wrap returns.
		errType.SetLocation(1)
	}
	return wrapped
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:18,代码来源:errors.go

示例3: handleActivityTask

func (a *ActivityWorker) handleActivityTask(activityTask *swf.PollForActivityTaskOutput) {
	a.ActivityInterceptor.BeforeTask(activityTask)
	handler := a.handlers[*activityTask.ActivityType.Name]

	if handler == nil {
		err := errors.NewErr("no handler for activity: %s", LS(activityTask.ActivityType.Name))
		a.ActivityInterceptor.AfterTaskFailed(activityTask, &err)
		a.fail(activityTask, &err)
		return
	}

	var deserialized interface{}
	if activityTask.Input != nil {
		switch handler.Input.(type) {
		case string:
			deserialized = *activityTask.Input
		default:
			deserialized = handler.ZeroInput()
			err := a.Serializer.Deserialize(*activityTask.Input, deserialized)
			if err != nil {
				a.ActivityInterceptor.AfterTaskFailed(activityTask, err)
				a.fail(activityTask, errors.Annotate(err, "deserialize"))
				return
			}
		}

	} else {
		deserialized = nil
	}

	result, err := handler.HandlerFunc(activityTask, deserialized)
	result, err = a.ActivityInterceptor.AfterTask(activityTask, result, err)
	if err != nil {
		if e, ok := err.(ActivityTaskCanceledError); ok {
			a.ActivityInterceptor.AfterTaskCanceled(activityTask, e.details)
			a.canceled(activityTask, e.Details())
		} else {
			a.ActivityInterceptor.AfterTaskFailed(activityTask, err)
			a.fail(activityTask, errors.Annotate(err, "handler"))
		}
	} else {
		a.ActivityInterceptor.AfterTaskComplete(activityTask, result)
		a.result(activityTask, result)
	}
}
开发者ID:uberbrodt,项目名称:swfsm,代码行数:45,代码来源:worker.go

示例4: NewInvalidConfigValue

// NewInvalidConfigValue returns a new InvalidConfigValue for the given
// info. If the provided reason is an error then Reason is set to that
// error. Otherwise a non-nil value is treated as a string and Reason is
// set to a non-nil value that wraps it.
func NewInvalidConfigValue(key string, value, reason interface{}) error {
	var underlying error
	switch reason := reason.(type) {
	case error:
		underlying = reason
	default:
		if reason != nil {
			underlying = errors.Errorf("%v", reason)
		}
	}
	err := &InvalidConfigValue{
		cause:  errors.NewNotValid(underlying, "GCE config value"),
		Key:    key,
		Value:  value,
		Reason: underlying,
	}
	err.Err = errors.NewErr("config value")
	err.Err.SetLocation(1)
	return err
}
开发者ID:imoapps,项目名称:juju,代码行数:24,代码来源:errors.go

示例5: newEmbed

func newEmbed(format string, args ...interface{}) *embed {
	err := &embed{errors.NewErr(format, args...)}
	err.SetLocation(1)
	return err
}
开发者ID:ehalpern,项目名称:go-mysql-elasticsearch,代码行数:5,代码来源:error_test.go

示例6: minVersionError

func minVersionError(minver, jujuver version.Number) error {
	err := errors.NewErr("charm's min version (%s) is higher than this juju environment's version (%s)",
		minver, jujuver)
	err.SetLocation(1)
	return minJujuVersionErr{&err}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:6,代码来源:client.go

示例7: NoAddressf

// NoAddressf returns an error which satisfies IsNoAddress().
func NoAddressf(format string, args ...interface{}) error {
	newErr := errors.NewErr(format+" no address", args...)
	newErr.SetLocation(1)
	return &noAddress{newErr}
}
开发者ID:imoapps,项目名称:juju,代码行数:6,代码来源:network.go

示例8: NewDeserializationError

// NewDeserializationError constructs a new DeserializationError and sets the location.
func NewDeserializationError(format string, args ...interface{}) error {
	err := &DeserializationError{Err: errors.NewErr(format, args...)}
	err.SetLocation(1)
	return err
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:6,代码来源:errors.go

示例9: NewUnsupportedVersionError

// NewUnsupportedVersionError constructs a new UnsupportedVersionError and sets the location.
func NewUnsupportedVersionError(format string, args ...interface{}) error {
	err := &UnsupportedVersionError{Err: errors.NewErr(format, args...)}
	err.SetLocation(1)
	return err
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:6,代码来源:errors.go

示例10: NewUnexpectedError

// NewUnexpectedError constructs a new UnexpectedError and sets the location.
func NewUnexpectedError(err error) error {
	uerr := &UnexpectedError{Err: errors.NewErr("unexpected: %v", err)}
	uerr.SetLocation(1)
	return errors.Wrap(err, uerr)
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:6,代码来源:errors.go

示例11: NewNoMatchError

// NewNoMatchError constructs a new NoMatchError and sets the location.
func NewNoMatchError(message string) error {
	err := &NoMatchError{Err: errors.NewErr(message)}
	err.SetLocation(1)
	return err
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:6,代码来源:errors.go

示例12: NewCannotCompleteError

// NewCannotCompleteError constructs a new CannotCompleteError and sets the location.
func NewCannotCompleteError(message string) error {
	err := &CannotCompleteError{Err: errors.NewErr(message)}
	err.SetLocation(1)
	return err
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:6,代码来源:errors.go

示例13: NewPermissionError

// NewPermissionError constructs a new PermissionError and sets the location.
func NewPermissionError(message string) error {
	err := &PermissionError{Err: errors.NewErr(message)}
	err.SetLocation(1)
	return err
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:6,代码来源:errors.go

示例14: NewBadRequestError

// NewBadRequestError constructs a new BadRequestError and sets the location.
func NewBadRequestError(message string) error {
	err := &BadRequestError{Err: errors.NewErr(message)}
	err.SetLocation(1)
	return err
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:6,代码来源:errors.go

示例15: NotAvailable

// NotAvailable returns an error which satisfies IsNotAvailable.
func NotAvailable(thing string) error {
	return &notAvailable{
		errors.NewErr(thing + " is not available"),
	}
}
开发者ID:howbazaar,项目名称:juju,代码行数:6,代码来源:errors.go


注:本文中的github.com/juju/errors.NewErr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。