Skip to main content

Notifications

Grabbing Error Message From Failed Run

Jcook Profile Picture Jcook 7,770

Summary:

We will be using the Try - Catch structure to build out this solution.

This will involved 2 Scopes - Scopes are an action in Power Automate that can hold other actions.

 

Steps:

For our 2 Scopes we will name,

Scope1 = Try

Scope2 = Catch

 

In our Try scope we put all our regular actions that we expect to run on a successful run

In our Catch scope we put what we want to execute if anything from our Try has failed.

 

This is what it should look like:

Jcook_0-1597681660745.png

 

Now we want to configure run after on the Catch scope to enable this cope to run only if Try has failed

To do this, click the 3 dots on the Catch action, and click Configure run after, and check the has failed box

Jcook_1-1597681907678.png

Click Done.

 

Now it should look like this:

Jcook_2-1597681986802.png

Notice the red arrow, this is stating there is a Configure run after enabled.

 

Now in our Catch scope add a Compose action, we will use the expression result( )

The syntax for result() is:

 

 

result('ActionName')

 

 

So my expression looks like this:

 

 

result('Scope_-_Try')

 

 

Jcook_4-1597682104304.png

**NOTE: The result expression does not show up in the list of expressions when typing out the expression**

 

Next add a Parse JSON action, and pass the Outputs from the Compose.

Jcook_5-1597682575585.png

Here is the schema:

 

 

{
 "type": "array",
 "items": {
 "type": "object",
 "properties": {
 "name": {
 "type": "string"
 },
 "startTime": {
 "type": "string"
 },
 "endTime": {
 "type": "string"
 },
 "trackingId": {
 "type": "string"
 },
 "clientTrackingId": {
 "type": "string"
 },
 "clientKeywords": {
 "type": "array",
 "items": {
 "type": "string"
 }
 },
 "code": {
 "type": "string"
 },
 "status": {
 "type": "string"
 },
 "error": {
 "type": "object",
 "properties": {
 "code": {
 "type": "string"
 },
 "message": {
 "type": "string"
 }
 }
 }
 },
 "required": [
 "name",
 "startTime",
 "endTime",
 "trackingId",
 "clientTrackingId",
 "clientKeywords",
 "code",
 "status",
 "error"
 ]
 }
}

 

 

 

After the Parse JSON action, add a Select action, this action will be used to only grab the data we want.

Put the Body in the From field, and than build out what information you want to see in this message.

Jcook_6-1597682808356.png

 

Here is a sample run:

Jcook_7-1597683543397.png

 

This Select output can than be used inside a Send email action or a Teams message.

 

 

 

Thanks for reading!

Check out my blog on flowaltdelete

Comments

*This post is locked for comments

  • jiwhite Profile Picture jiwhite 498
    Posted at
    Grabbing Error Message From Failed Run

    I prefer to use selects and filter after the compose to get the errors, then join them.

    jiwhite_0-1716401846480.png

     

  • jiwhite Profile Picture jiwhite 498
    Posted at
    Grabbing Error Message From Failed Run

    @VictorTek Please post a new question with an anonymized example of your code and the error.

  • VictorTek Profile Picture VictorTek 127
    Posted at
    Grabbing Error Message From Failed Run

    Hi

     

    I am trying function parse json in the try scope. Cannot get the result('try') as error message. It is copying again the json instead of error from the parse json output

     

    do you know any solution?

     

    kind regards

     

     

  • jleystral Profile Picture jleystral 97
    Posted at
    Grabbing Error Message From Failed Run

    Thank you guys.

    Since grabbing the error code (top right in screenshot) works perfectly when the failed action is not within a condition step, I was hoping there may be a trick to also get it when it's within a condition.

     

    jleystral_0-1673850035797.png

     

    (Here it works perfect to forward the error to the user because it's not within a condition step)

     

    Now I can tell the user that it is unfortunately not possible. Thanks again.

  • Marcel Lathouwers Profile Picture Marcel Lathouwers 236
    Posted at
    Grabbing Error Message From Failed Run

    @jleystral

    @jiwhite is correct. This is the detail that can be reported back to the user. 

    The error that is shown on the top right of your screenshot is hard (maybe impossible) to grab during execution time. 

  • jiwhite Profile Picture jiwhite 498
    Posted at
    Grabbing Error Message From Failed Run

    The error is there.  You need to make sure that you examine all of the keys for errors.

    jiwhite_0-1673625816973.png

     

  • jleystral Profile Picture jleystral 97
    Posted at
    Grabbing Error Message From Failed Run

    Hi everyone, 

     

    Can someone help me?
    I did this approach and everything works fine until it comes to a failed action within a condition. 

    The function "result('flow')" gives me just the failed condition step and no error message:

    jleystral_0-1673598889228.png

     

     

     

     

     

    {
     "name": "Bedingung",
     "inputs": {
     "expressionResult": false
     },
     "startTime": "2023-01-13T07:27:01.5077518Z",
     "endTime": "2023-01-13T07:37:05.8483813Z",
     "trackingId": "9015a800-d460-4d6f-9f34-236047073bc1",
     "clientTrackingId": "08585280751417503691732659688CU137",
     "code": "ActionFailed",
     "status": "Failed",
     "error": {
     "code": "ActionFailed",
     "message": "An action failed. No dependent actions succeeded."
     }
     },
     {
     "name": "Verzögern_3",
     "inputs": {
     "interval": {
     "unit": "Minute",
     "count": 5
     }
     },
     "startTime": "2023-01-12T13:55:45.067581Z",
     "endTime": "2023-01-12T14:00:45.2238881Z",
     "trackingId": "34c2976d-182c-4ccc-b81f-f47526ef6866",
     "clientTrackingId": "08585280751417503691732659688CU137",
     "code": "OK",
     "status": "Succeeded"
     }
    ]

     

     

     

    As you see, he even lists the first succeeded step within the "if no" part but i won't get any information about the failed step.

    I need to grab the error code to forward it to the responsible person.

     

    Many thanks in advance.

     

  • jiwhite Profile Picture jiwhite 498
    Posted at
    Grabbing Error Message From Failed Run

    Outputs is an array, so the schema can't be used directly without Apply to each.  Instead, I use the following as the input to Parse JSON to extract the JSON from the output:

    outputs('Compose_Revert_Result')[0]
     
  • TayM Profile Picture TayM
    Posted at
    Grabbing Error Message From Failed Run

    Ah thanks @Mglat . That really helped when you said that every connector returns the error result in a different way.  I was under the impression that the schema should always have an error attribute like below but in my scenario the error message was hidden within 'outputs/body/message' and the error code in 'code'. There was no such distinct 'error' attribute in my schema which confused me. Thank you.

    "error": {
     "type": "object",
     "properties": {
     "code": {
     "type": "string"
     },
     "message": {
     "type": "string"
     }
     }
     }

     

  • Marcel Lathouwers Profile Picture Marcel Lathouwers 236
    Posted at
    Grabbing Error Message From Failed Run

    @TayM My first sugestion would be to remove the 'required' part from your the parse schema. Secondly you can try to create your own schema, by grabing the output of the Try scope and paste it in the parse step using the 'generate from sample'. Again I would recommend to remove the required part.

     

    Be aware that every connector is returning the error result in a different way, so upfront it is not always clear how to handle this within the parse. Also if you have nested steps e.g. apply-to-each loop, these will create a seperate result() and it will not be presentent on the highest level (at the Try scope level)