Power Automate: basic error handling

Why?

One of the first posts on error handling in a Flow of Power Automate (previously Microsoft Flow), I read was that of Serge Luca (Doctor Flow): PATTERN FOR MICROSOFT FLOW ERROR HANDLING so if you ever have the chance to attend one of his sessions: go for it! 💡

What?

This post is a minum effort on how failed flows can come together in one place for (centralized) support.

How?

First some pointers on big complex Flows:

  • try to use Scopes to group certain actions together for readability
  • try to use Compose where possible instead of a Variable for performance

1) Create a Scope Control for your error handling not only to keep the Flow more readible but also to easily copy the whole scope and paste it elsewehere in the Flow or even paste it in other Flows:

2) In the Scope Control place the relevant actions that you want to happen when an error has occured:

I choose to add a minimum of 5 actions:

🚀 A Compose action where I add the receiver of the error notification. Normally a shared mailbox but also a useful place to let other Flow makers know who owns this flow.

🚀 A Compose action where I specify the Subject of the error notification. I use Flow parameters that are variable with the specific Flow.

Error=@{workflow()['tags']['flowDisplayName']} in ENV=@{workflow()['tags']['environmentName']}

🚀 A Compose action where I add all additional information for trouble shooting related to the specific run. Notice the HTML hyperlink directly to the Flow run. 💪

<p>Error in Flow<br>
<a href="https://flow.microsoft.com/manage/environments/@{workflow()['tags']['environmentName']}/flows/@{workflow()['name']}/runs/@{workflow()?['run']['name']}">Open run flow @{workflow()['tags']['flowDisplayName']}</a><br>
<br>
Environment=@{workflow()['tags']['environmentName']}<br>
Flow ID=@{workflow()['name']}<br>
Run ID=@{workflow()?['run']['name']}<br>
Flow Display name=@{workflow()['tags']['flowDisplayName']}</p>

🚀 A Send an email action to inform the receiver by email.

I refer to the Compose actions because I have noticed a bug in the Send an email (V2) action where the Body property reverts back to non-HTML when you open the action at a later moment. See the screenshot below:

If you leave it like this –> the email will not send the text as HTML and the Hyperlink with direct link to the flow run will not work anymore. So use the Compose actions and never touch the Send an email action again.

🚀 And last but not least a Terminate action to easily identify the failed Flow in the big overview of completed Flows (otherwise the last action of the Flow being the Scope for error handling would complete successfully and then the Flow status would be Succeeded 🤓)

3) Then place that Scope for error handling in the right place(s) based on Configure run after settings that suit your needs:

In my case I placed it on the bottom of the Flow because the business rules of the process stated that the last action of every scenario would be to update the triggering item of the request. Thus the Update step should always succeed and I would only need one place to handle possible errors:

ℹ has failed would start this scope when the previous Update step would fail
(use this checkbox when the scope is only depending on the previous step)

ℹ is skipped would start this scope when the previous Update step was not run at all
(use this checkbox when the scope is depending on any of the steps above –> if any of the steps above would error out, the Update step would be skipped so then this Scope would run)

ℹ has timed out would start this scope when the previous Update step has reached its runtime limit / has timed out
(use this checkbox when a previous step has a runtime limit like a Modern Approval which cannot run longer than a fixed number of days)

TIP: to test a fail and make sure a Flow will not succeed, just create a simple action like Compose with an expression that always fails: substring(‘123’,5,10) 💡.

Leave a comment