コード例 #1
0
ファイル: memory.go プロジェクト: lysu/go-saga
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
}
コード例 #2
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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
}
コード例 #3
0
ファイル: worker.go プロジェクト: uberbrodt/swfsm
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)
	}
}
コード例 #4
0
ファイル: errors.go プロジェクト: imoapps/juju
// 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
}
コード例 #5
0
func newEmbed(format string, args ...interface{}) *embed {
	err := &embed{errors.NewErr(format, args...)}
	err.SetLocation(1)
	return err
}
コード例 #6
0
ファイル: client.go プロジェクト: AlexisBruemmer/juju
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}
}
コード例 #7
0
ファイル: network.go プロジェクト: imoapps/juju
// 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}
}
コード例 #8
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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
}
コード例 #9
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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
}
コード例 #10
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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)
}
コード例 #11
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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
}
コード例 #12
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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
}
コード例 #13
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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
}
コード例 #14
0
ファイル: errors.go プロジェクト: voidspace/gomaasapi
// 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
}
コード例 #15
0
ファイル: errors.go プロジェクト: howbazaar/juju
// NotAvailable returns an error which satisfies IsNotAvailable.
func NotAvailable(thing string) error {
	return &notAvailable{
		errors.NewErr(thing + " is not available"),
	}
}
コード例 #16
0
ファイル: network.go プロジェクト: bac/juju
// NoAddressError returns an error which satisfies IsNoAddressError(). The given
// addressKind specifies what kind of address is missing, usually "private" or
// "public".
func NoAddressError(addressKind string) error {
	newErr := errors.NewErr("no %s address", addressKind)
	newErr.SetLocation(1)
	return &noAddress{newErr}
}