BrianB
BuildShip17mo ago
21 replies
Brian

Cannot access looped Node items if they were failing (undefined)

Imagine a workflow that has some nodes within a loop. These nodes could potentially fail, but that's okay, so I set an "On Fail" to "Ignore". Now after that loop I have another node that accesses one of the nodes within that loop. Due to the fact that this node is within a loop, I will get an array variable when referencing it.
So far so good, but when I try to access that array's items with an index, it throws the error "Cannot read properties of undefined (reading '0')". I am not sure why, because even though if a node failed within the loop, it would still have an "undefined" at that index of the array.
I attached my loop array as an image for reference.
To be exact, consider this array as "array1" and "array2" is an array that has the exact same length, but without any undefined values. My goal is to retrieve all items from array2 that would match an "undefined " value from array1 like this:
array2.filter((_, index) => array1[index] === undefined.

My array clearly has at least an "undefined" at every index, so why am I getting this error?
Screenshot_2024-09-10_at_14.57.35.png
Solution
@Brian The issue was that the object properties were getting accessed on undefined values.For now, you can use the optional chaining whenever you encounter such a condition. We have modified the conditions a bit on the following nodes: 1. Branch Check for failed Prompts, 2. Retry Grounded-SAM, 3. Replace "Undefined" from Array. you can test your workflow again.

Sent you can email with the fix and more details, you can followup on the email with more question.
Was this page helpful?