ActionComplete / ActionFailed called after Action completion

The worker now calls ActionComplete or ActionFailed on state, depending
on the success state of the Action and any errors.

The hook is set to an error state if the Action hook is missing, or if
other errors take place during hook execution.  If the Action hook sets
a fail state, the Hook will not error, rather the Action will fail.

DEPENDS: https://github.com/juju/juju/pull/527
If callError is of type error, then the better use is
`errors.Annotate(callError, "some description")`


On Wed, Aug 27, 2014 at 9:42 PM, Jesse Meek <notifications@github.com>
wrote:

> In worker/uniter/context.go:
>
> > @@ -306,7 +333,25 @@ func (ctx *HookContext) finalizeContext(process string, err error) error {
> >  		}
> >  		rctx.ClearCache()
> >  	}
> > -	return err
> > +	// This short-circuits the Action related error, which otherwise is
> > +	// overwritten.  If ctx.actionTag was not empty, it is an Action.
> > +	if err != nil || (ctx.actionTag == names.ActionTag{}) {
> > +		if (ctx.actionTag == names.ActionTag{}) {
> > +			return err
> > +		}
> > +		// Otherwise, it was an action, but there was an error.
> > +		callError := ctx.state.ActionFail(ctx.actionTag, err.Error())
> > +		if callError != nil {
> > +			// Oh dear.  Stack the errors.  Best we can do.
> > +			err = errors.New(fmt.Sprintf("Action API error %s on top of error: %s", callError.Error(), err.Error()))
>
> You can use errors.Errorf("Action.... %s", callError.Error())
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/juju/juju/pull/617/files#r16769899>.
>