Power Automate Standards: Error-Handling

Power Automate Standards: Error-Handling
Table of Contents
• Try, Catch, Finally PatternGroup Multiple Actions Inside Of A Scope ActionTerminate The Flow With A Status Of Success Or FailureNotify The Process Owner Of The Flow FailureGet The Flow Error Message For The Failed ActionInclude The Flow Run History URL




Try, Catch, Finally Pattern

Check for errors and tell Power Automate how to handle them at possible failure points in the flow.

The Try, Catch, Finally pattern for error-handling pattern is found in most programming languages:

  • Try – Attempt to execute one or more flow actions
  • Catch – When an error occurs, do these steps next
  • Finally – always run these actions whether the previous actions succeeded or failed

Here’s how to create the Try, Catch, Finally pattern with Power Automate.



Configure the “run after settings” as shown for the flow actions below.




Group Multiple Actions Inside Of A Scope Action

When multiple actions have the same error-handling requirements place them inside a scope action. A scope action holds a set of other actions.



Then configure the run-after requirements for the scope. Now any action inside the scope will trigger the error-handling behavior.




Terminate The Flow With A Status Of Success Or Failure

A flow using error-handling will continue to run after it encounters an error. It will end with a status of succeeded even though there was a failure. To overcome this issue, include terminate actions as the final flow steps to ensure to correct status is displayed in the flow run history.




Notify The Process Owner Of The Flow Failure

Alert the business process owner when the flow fails to let them know there was an issue. If no one is notified when the flow fails then it will not get fixed and could continue to happen.




Get The Flow Error Message For The Failed Action

The reason for flows failures are not often not known in advance. This makes writing an error message before-hand difficult. By using the actions expression we can extract a useful error message from the flow action that failed.



Add a failure reason section to the flow failure notification and use this expression.

actions('Compose:_Test_Value')?['error]'?['message']



When the flow fails an error message will appear in the flow run history.



Then the message gets included in the flow failure notification to the business process owner who will take action on it.




Include The Flow Run History URL

A clickable link to the flow run details should be added to the failure notification. The message can be forwarded to a developer who can quickly identify the failed flow run in the history. Then they can review the issue and diagnose the problem. To do this, use this following coding pattern:



Flow expression #1 gets the environment’s unique identifier.

outputs('Compose:_Get_Workflow_Details')?['tags']?['environmentName']



Flow expression #2 extracts the flow’s unique identifier.

outputs('Compose:_Get_Workflow_Details')?['name']



Flow expression #3 finds the flow run’s unique identifier.

outputs('Compose:_Get_Workflow_Details')?['run']?['name']


The failure notification email looks like this:






Questions?

If you have any questions or feedback about Power Automate Standards: Error-Handling please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Subscribe
Notify of
guest

3 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Sarah
Sarah
4 months ago

This is EXTREMELY helpful and i’ve applied it to a few of my flows but i have picked up an issue which i’m wondering if you have a solution for.

It seems when the Try has a condition or apply to each, any error that comes up within that will show as “Action Failed. No Dependent action succeeded. So in my scenario I have an action that runs a PAD process but i don’t see the actual PAD failure only that useless condition failure.

Attached a picture for your reference.

Any guidance?

Screenshot 2023-11-30 124115.jpg
Gianluca M
Gianluca M
3 months ago

Hi Matthew

Great article! I came across it as I’m just doing the same.

Just a small note:

Instead of using the actions() function (which you need to apply to a specific action that might fail) I use the result() function for the “Try Scope” (result(‘Scope_-_Try’)). It returns an array which you can further filter for ‘Status’ equals ‘Failed’ and then use [‘Error’]?[‘message’] to include in the notification mail.

BR
Gianluca