Capture an Error in a For Each loop in ADF

Gareth Parry 20 Reputation points
2025-04-23T09:25:07.15+00:00

Hi,

I have a pipeline that includes a ForEach loop. On occasion the pipeline fails in the for each loop, but the only error message i get is "Activity failed because an inner activity failed". How do i get to, or capture the actual error?

thanks

Gareth

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,509 questions
0 comments No comments
{count} votes

Accepted answer
  1. Venkat Reddy Navari 1,855 Reputation points Microsoft External Staff Moderator
    2025-04-23T10:41:11.2566667+00:00

    Hi @Gareth Parry When a ForEach loop fails in Azure Data Factory, you often get a generic message like "Activity failed because an inner activity failed." To capture the actual error details, here’s what you can do:

    1. Check Inner Activities: Go to the Monitor tab, click on the ForEach activity, then expand each failed iteration. You'll be able to see which inner activity failed and why.
    2. Use Expressions to Capture Errors: You can access detailed error info from the activity object. Normally you use:
         @activity('MyActivityName').output
      
      But to get the error message when something fails, use:
         @activity('MyActivityName').error.message
      
      This is especially useful inside error-handling logic, such as a Try-Catch pattern or an If Condition block, where you want to log or route errors.
    3. Optional Logging: Consider appending the error message to a variable or logging it to a table or blob for future analysis.

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Nandan Hegde 35,191 Reputation points MVP Moderator
    2025-04-23T11:24:47.0133333+00:00

    You need to capture the error message of all activities individually within the foreach and preserve it in a variable and you can reference it outside the for each. you can refer below blog : https://datasharkx.wordpress.com/2021/08/19/error-logging-and-the-art-of-avoiding-redundant-activities-in-azure-data-factory/ here to understand how to collate


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.