As follows, I think ctx.Fail to be accessibe by the user function is not an idiomatic Go API. The JavaScript and Java support use ctx.Fail to indicate a failed context and the user function would return a failure reply to the proxy.
In case of a context to be failed, the error value for the context failure is set by ctx.Fail() but it also could be idiomatcally returned as an error value by a command handled function. This would remove the unusual sequence of
// AddItem implements the AddItem command handling of the shopping cart service.
func (sc *ShoppingCart) AddItem(ctx *eventsourced.Context, li *shoppingcart.AddLineItem) (*empty.Empty, error) {
if li.GetQuantity() <= 0 {
ctx.Fail(fmt.Errorf("cannot add negative quantity of to item %s", li.GetProductId()))
return nil, nil
}
ctx.Emit(&domain.ItemAdded{
Item: &domain.LineItem{
ProductId: li.ProductId,
Name: li.Name,
Quantity: li.Quantity,
}})
return &empty.Empty{}, nil
}