Example #1
0
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
}
Example #2
0
// 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
}
Example #3
0
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)
	}
}
Example #4
0
// 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
}
func newEmbed(format string, args ...interface{}) *embed {
	err := &embed{errors.NewErr(format, args...)}
	err.SetLocation(1)
	return err
}
Example #6
0
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}
}
Example #7
0
// 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}
}
Example #8
0
// 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
}
Example #9
0
// 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
}
Example #10
0
// 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)
}
Example #11
0
// 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
}
Example #12
0
// 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
}
Example #13
0
// 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
}
Example #14
0
// 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
}
Example #15
0
// NotAvailable returns an error which satisfies IsNotAvailable.
func NotAvailable(thing string) error {
	return &notAvailable{
		errors.NewErr(thing + " is not available"),
	}
}
Example #16
0
File: network.go Project: 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}
}