Skip to content

Commit 45ca926

Browse files
committed
Fix array check for collection
1 parent 77ee017 commit 45ca926

File tree

1 file changed

+9
-2
lines changed
  • apps/sim/executor/orchestrators

1 file changed

+9
-2
lines changed

apps/sim/executor/orchestrators/loop.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ export class LoopOrchestrator {
8484

8585
case 'forEach': {
8686
scope.loopType = 'forEach'
87-
if (!Array.isArray(loopConfig.forEachItems)) {
87+
// Resolve items first - forEachItems can be a string, reference, array, or object
88+
const items = this.resolveForEachItems(ctx, loopConfig.forEachItems)
89+
90+
// Check if resolution failed (empty result from non-empty input)
91+
const hasInput =
92+
loopConfig.forEachItems !== undefined &&
93+
loopConfig.forEachItems !== null &&
94+
loopConfig.forEachItems !== ''
95+
if (hasInput && items.length === 0) {
8896
const errorMessage =
8997
'ForEach loop collection is not a valid array. Loop execution blocked.'
9098
logger.error(errorMessage, { loopId, forEachItems: loopConfig.forEachItems })
@@ -95,7 +103,6 @@ export class LoopOrchestrator {
95103
scope.condition = buildLoopIndexCondition(0)
96104
break
97105
}
98-
const items = this.resolveForEachItems(ctx, loopConfig.forEachItems)
99106
const originalLength = items.length
100107

101108
if (originalLength > DEFAULTS.MAX_FOREACH_ITEMS) {

0 commit comments

Comments
 (0)