all Technical posts

Logic App Exception Handling With The Result Function

In this blog post, we will take a look at the result function and how to use this within Logic Apps for exception handling purposes.

"An action failed. No dependent actions succeeded."

Most of you working with Logic Apps are probably familiar with the “An action failed. No dependent actions succeeded” exception that might occur within a Logic App. Unfortunately, this message does not offer much insight into the actual error and what might have gone wrong.

This starts to become a bigger issue once your production environment grows and the administrators need more time to figure out what actually went wrong within the failed Logic Apps.

To improve on this situation we can use the result function in combination with scopes, to try and get as much information about the exception as possible.

Setting Up Scopes

First, we start by introducing scopes withing the Logic App. There are generally two main scopes:

The first scope contains the actual implementation; for example, a call to an HTTP endpoint. The second scope will handle the exceptions that might occur during the first scope. Think of this like a try-catch setup.

The exception handling scope is where we will place our functionality, to try and retrieve as much error information as possible.

The Result Function

To achieve this, we will use the result function (https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#result). As the documentation states, this function allows us to return the results from the specified action(s).

Using the result function to get the results from our scope, we can then filter out the action that failed and get its error message. This can then be used in a Terminate shape to make sure the Logic App terminates with the actual error message, instead of the generic “An action failed. No dependent actions succeeded” message.

The exception handler scope contains the following actions:

The code is as follows:

“Filter_Scope_Result”: {
    “inputs”: {
        “from”: “@result(‘Scope’)”,
        “where”: “@equals(item()[‘status’], ‘Failed’)”
    },
    “runAfter”: {},
    “type”: “Query”
},
“Terminate”: {
    “inputs”: {
        “runError”: {
            “code”: “@body(‘Filter_Scope_Result’)?[0]?[‘code’]”,
            “message”: “@coalesce(body(‘Filter_Scope_Result’)?[0]?[‘error’]?[‘message’], concat(‘\”‘, body(‘Filter_Scope_Result’)?[0]?[‘outputs’]?[‘body’], ‘\”‘))”
        },
        “runStatus”: “Failed”
    },
    “runAfter”: {
        “Filter_Scope_Result”: [
            “Succeeded”
        ]
    },
    “type”: “Terminate”
}
Basically, what we do here is select the results from the scope and filter out the action that failed. This is then used in the Terminate shape, where we use the coalesce function to either return the error message of the failed action, or if this error message is not available, use the output of the failed action.
Using this setup, we get a nice error message from our scope which is then used to terminate the Logic App. For example:

Nested Actions

After implementing this setup in our Logic Apps, I noticed that after a while I was sometimes still getting the basic “An action failed. No dependent actions succeeded” error message. As it turns out, the @result expression only gives the result of all the actions on the “first-level”. Any nested actions are not listed. It just shows that, for example, the Condition shape failed, but not which step within the condition and with only the basic error message showing.

I solved this by changing the @result expression to include multiple results. For example, if we have a Logic App that contains a Condition within an Until within the main Scope, the @result would look like this: “@union(result(‘Condition’), result(‘Until’), result(‘Scope’)). This combines all nested results, and allows the filter to get the actual error message!

Note: the @result expression does not allow any kind of variable, so I had to use the @union to combine all results.

Wrapping Up

It is important to give your administrators as much valuable information if an exception occurs. The “An action failed. No dependent actions succeeded” message only shows that something went wrong, and not specifically what.

The result function combined with scopes allows us to retrieve the actual error message for a failed Logic App, and gives your administrators much more information to work with!

Thanks for reading,

Pim

Subscribe to our RSS feed

Hi there,
how can we help?

Got a project in mind?

Connect with us

Let's talk

Let's talk

Thanks, we'll be in touch soon!

Call us

Thanks, we've sent the link to your inbox

Invalid email address

Submit

Your download should start shortly!

Stay in Touch - Subscribe to Our Newsletter

Keep up to date with industry trends, events and the latest customer stories

Invalid email address

Submit

Great you’re on the list!