A Guide to Error Handling in Power Automate Flow

Link within an email warning of an error opens the Flow instance

I would like to share how I am currently dealing with errors, within Cloud Flows, using a strategy of actively informing administrators and/or support staff that something has gone wrong.

We are going to start by creating a Power Platform Solution and adding environment variables, a single connection reference and Instant Cloud Flow.

By the end of this post, my intention for you, the reader, to be able to recreate the solution.

Power Automate Solution components
Power Automate Solution components

Building a PoC (proof of concept) Flow

Start by creating a new Power Platform Solution called “PoC Flow Error Handling”. With a few exceptions I almost always create a Power Platform Solution, which has plenty of advantages (out of the scope for this post).

Next, add the following environment variables, setting the default and/or current values to match your environment:

Display NameDescriptionDefault ValueCurrent Value
Email: IT AdminIT Admin team members who will manage and support this solution.it.admin@test.comdev.admin@test.com
Environment NameA label used to describe the environment e.g., DEV, UAT or leave blank for Production. DEV
Environment RegionGet this value from the Flow makers portal unitedkingdom
Environment Variables

Add a connection reference for Office 365 Outlook:

Display NameDescriptionConnectorConnection
PoC FEH: Office 365 OutlookOffice 365 Outlook connection reference.Office 365 Outlook connection reference.service.acc@test.com
Connection Reference

Add an Instant Cloud Flow to the solution called ‘Test Error Handling’.

Open the Cloud Flow and add a Yes|No (Boolean) parameter to the Trigger called ‘Throw Error’.

Directly under the Trigger, I add the following variables:

NameTypeValueNote
FlowInstanceURLString@{concat(‘https://’,parameters(‘Environment Region (sjlewis_EnvironmentRegion)’),’.flow.microsoft.com/manage/environments/’,workflow().tags.environmentName,’/flows/’,workflow().name,’/runs/’,workflow().run.name)}Contains the calculated Flow instance’s URL.
FlowInstanceNameStringTest Error HandlingContains the Flow instance’s name.
CauseErrorBoolean Used for demo purpose.
Power Automate Flow Variables
Power Automate Instant Flow trigger and variables
Power Automate Instant Flow trigger and variables

After variables add a “Condition” step, which is checks the ‘Throw Error’ value:

  • If TRUE then set the CauseError parameter to NULL
  • If FALSE then set the CauseError parameter to FALSE

Note: setting a Boolean variable to NULL will cause the Flow to error.

How to causing an error within a Microsoft Flow
If condition is true, then cause an error within the Microsoft Flow

After the condition, I add a branch and a step to each side:

  • The “Terminate: Succeeded” step implements the default “is useful” run after condition.
  • The “Scope: Error Handling” step implements the “has failed, is skipped, has timed out” run after conditions.
Error handling within a Power Automate Flow
Error handling within the Power Automate Flow

All the error handling “magic” happens within “Scope: Error Handling” step:

  1. The “Compose: Error Handing | Email Subject” step, builds the email subject and error title.
  2. The “Compose: Error Handing | Email Body” step, builds the email body and error message.
  3. The “Send an email (V2)” step sends the email to the email addresses set within the ” Email: IT Admin” environment variable, with the importance set to high.
  4. The “Terminate: Error Handing” step sets the instance of the flow as failed.
Error Handling Cloud Flow
Cloud Flow with error handling steps

Running the Flow

Either run the Flow by clicking on “Test” within the edit screen or clicking on “Run” within Flow’s the details page. Next, select the “Throw Error” toggle switch and then click on “Run Flow”. The Flow will fail as expected and send an email to the address set within the environment variable.

If you would like to test the successful branch, leave the “Throw Error” toggle switch unselected (false or off).

Running a Power Automate Intant Cloud Flow
Running the Power Automate Intant Cloud Flow
Email with the subject of "ERROR: 'Test Error Handling' Flow failed (DEV environment)"
Email subject “ERROR: ‘Test Error Handling’ Flow failed (DEV environment)”
Email Link Opens Flow Instance
Flow instance run history

Summary

I like this technique, because it informs the admin or support directly via an email, which is flagged as high priority, and includes a link directly to the failed instance. This reduces the possibility of an error being missed and saves time locating the cause.

The unmanaged Power Platform Solution can be downloaded from my Power-Platform GitHub repository.

Update

Thank you

Thank you to MacKenzie Bernard for the beer, much appreciated.

Categories

Recent Posts

Buy Siôn a beer…

If you have found my website useful and would like to buy me a beer, please click on this Donate PayPal button.

%d bloggers like this: