Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin 35 posts 159 karma points
    Nov 10, 2016 @ 19:00
    Kevin
    0

    How to fail a task chain

    I am just wondering how to correctly fail a task chain method. I may misunderstand them.

    I have a custom task in the OrderPreparationOrderCreate.

    This is fired my adding a payment to the invoice.

    var attempt = invoice.AuthorizeCapturePayment(cash.Key);
    if (!attempt.Payment.Success)
    {
        // TODO: handle the error
    }
    

    My custom task then obviously succeeds or fails. Success is easy to handle.

    return Attempt<IOrder>.Succeed(value);
    

    However if I fail:

    return Attempt<IOrder>.Fail(value);
    

    Then the Merchello core code throws a null reference exception. Is that the correct behaviour?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 10, 2016 @ 20:42
    Rusty Swayne
    0

    Hey Kevin,

    It looks like you're understanding fine - we may need to look at the underlying chain handler to see how it's handling failures (and not reaching the end of chain task - which is simply an internal terminator that returns the value).

    Where in the core code are you seeing the exception?

  • Kevin 35 posts 159 karma points
    Nov 11, 2016 @ 08:42
    Kevin
    0

    I have added a task to the OrderPreparationOrderCreate task chain. The code below should reproduce produce the issue.

    merchello.config

    <taskChain alias="OrderPreparationOrderCreate">
            <tasks>
                <task type="Merchello.Core.Chains.OrderCreation.ConvertInvoiceItemsToOrderItemsTask, Merchello.Core" />
                <task type="MyNamespace.MyClass.OrderCreatedTask, MyAssembly" />
            </tasks>
        </taskChain>
    

    Code

    namespace MyNamespace
    {
        public class MyClass : OrderCreationAttemptChainTaskBase
        {
            public OrderCreatedTask(IInvoice invoice)
                : base(invoice)
            {
            }
    
            public override Attempt<IOrder> PerformTask(IOrder value)
            {
                bool result = DoSomething();
                return Attempt<IOrder>.SucceedIf(result, value);
                // or more simply
                //return Attempt<IOrder>.Fail(value);
            }
        }
    }
    
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 11, 2016 @ 19:01
    Rusty Swayne
    0

    Thanks Kevin,

    Would you please add this to the issue tracker: http://issues.merchello.com so it does not fall off our radar ...

  • Kevin 35 posts 159 karma points
    Nov 12, 2016 @ 08:05
    Kevin
    0

    Created as M-1217 :)

Please Sign in or register to post replies

Write your reply to:

Draft