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?
Solution:Jump to 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....
17 Replies
AI Support Bot Information
<@112676328783802368> you can react on the relevant answer (message) with a ✅ in this thread when you think it has been solved, by the bot or by a human!
Anyone can react on this message with a ❌ if the GPT bot is unhelpful or hallucinating answers.
Please note: Team members will review and answer the questions on best efforts basis.
Here, array2.filter((_, index) => array1[index] === undefined. you are checking if the item value of the array is undefined, but the whole result value is undefined. We'll check this and update you.
Okay, do you need a workflow example or do you understand the flow that I described completely? (I was also wondering what version would be sent if I write a Support ticket in the BuildShip app and add my workflow. Is it giving you a copy of that workflow in this very moment or do you also see the changes that I made afterwards?
you can share as well, when you submit via support it shares the current version (irrespective of the deployment)
Okay, I just shared a stripped down version via the Support button. Do you also see what I have set in the test body or would we normally have to give it to you too?
@Brian we are now tracking this as an issue, seems to be an issue with accessing undefined values, we'll update you on the fix.
@Gaurav Chadha Are there any news on this?
Hey @Brian, it's in progress, we'll provide an update on fix this week. Thank you for your patience.
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.
@Gaurav Chadha This seems not to work. I get an "Unexpected end of JSON Input" error on the first node you inserted the condition. Is this ID there a node id? Because my whole workflow has no such ID, so I wonder where this is coming from
It is the Id from the looped items not, if you check the logs, it matches the undefined condition correctly. you can check the logs on which input this error is coming on the execute workflow node.
@Gaurav Chadha Ah yeah, so the remote workflow had some issues. I fixed that, but I am still curious where this id for the "loop items" is coming from. Is this some sort of a global internal id?
Cool, the Id is of the items that were getting mapped within the loop, we copied your default variable in the condition and removed the item ID and mapped it with the required onne and used optional chaining. It isn't any internal ID. We'll be pushing a default fix soon, as mentioned in the email.
Has this been fixed yet or are you currently working on a fix? For some reason it does not work anymore and I noticed that the loop items are now sometimes being mapped, for example:
ctx["root"]["277483-27472-3847"].map(_=>_["2848-284828-28482"])
The ID you mentioned before is the id of the node within the loop, right?the fix will be released along with the new version.
Yeah, the id is for one of the loop item
I sent you another app support request. My ID seems to not work and I don't understand what's wrong. I also can't see any workflow logs because they apparently never stop running.
Can you please CC Stefan from my workspace when you reply via E-Mail.
Sure, @Brian, you have added correct ID, and it is working, the issue seems ad the last parallel node, where the execution is not getting completed and getting stuck, checking and will revert here and on email asap.