Skip to content

Fix spread syntax runtime error on non-iterable values#7271

Closed
durga256 wants to merge 1 commit intomainfrom
fix/guard-array-spread-iterables
Closed

Fix spread syntax runtime error on non-iterable values#7271
durga256 wants to merge 1 commit intomainfrom
fix/guard-array-spread-iterables

Conversation

@durga256
Copy link
Copy Markdown

@durga256 durga256 commented Apr 13, 2026

Summary

  • Guard array spread sites that could receive non-iterable values at runtime, fixing "Spread syntax requires ...iterable[Symbol.iterator] to be a function" errors reported by Observe (7 events, 2 users over 7 days)
  • Replace ! non-null assertions and truthy checks with Array.isArray guards in reduceWebhooks webhook config transform — also fixes a silent data-loss bug where topics were dropped when existingSubscription[property] was undefined (the old ?.push would silently no-op)
  • Replace .map().flat() with .flatMap(... ?? []) in esbuild watcher deleteContexts to handle missing context entries
  • Remove fragile Map.get()! pattern in app-logs sources by using ?? [] fallback
  • Add tests for reduceWebhooks property-branch merging, covering the ??= [] initialization case

Why

Observe reports a "Spread syntax requires ...iterable[Symbol.iterator] to be a function" runtime error in the app slice. The strongest candidate is reduceWebhooks in the webhook config transform, where subscription data is spread using ! non-null assertions — if the data has unexpected shape, the spread throws. The Map.get()! in sources.ts is the only such pattern in the codebase and is fragile if the has() guard above is ever refactored away. The esbuild watcher uses flatMap as the idiomatic replacement for optional-chaining inside .map().flat().

Test plan

  • pnpm vitest run packages/app/src/cli/models/extensions/specifications/transform/app_config_webhook.test.ts — 9 tests pass (7 existing + 2 new)
  • pnpm vitest run packages/app/src/cli/services/dev/app-events/app-watcher-esbuild.test.ts — 8 tests pass
  • pnpm vitest run packages/app/src/cli/services/app-logs/sources.test.ts — 1 test passes
  • TypeScript compilation — no new errors in changed files

Copy link
Copy Markdown
Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@durga256 durga256 force-pushed the fix/guard-array-spread-iterables branch from f77632f to a95c924 Compare April 13, 2026 16:54
Replace unsafe non-null assertions and truthy guards with Array.isArray
checks before spreading webhook subscription properties in
reduceWebhooks. Use flatMap with nullish coalescing in esbuild watcher
deleteContexts. Remove fragile Map.get()! in app-logs sources.

Add tests for reduceWebhooks property-branch merging, covering the case
where the existing subscription's property array is initially undefined.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@durga256 durga256 force-pushed the fix/guard-array-spread-iterables branch from a95c924 to 0a614df Compare April 13, 2026 16:58
@durga256 durga256 marked this pull request as ready for review April 13, 2026 16:58
@durga256 durga256 requested a review from a team as a code owner April 13, 2026 16:58
Copilot AI review requested due to automatic review settings April 13, 2026 16:58
@durga256 durga256 marked this pull request as draft April 13, 2026 16:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a reported runtime error caused by spreading non-iterable values by adding safer array guards in webhook config transforms, and applies similar defensive patterns in a couple of other collection/iteration sites in the CLI.

Changes:

  • Harden reduceWebhooks merging logic using Array.isArray + ??= [] initialization to avoid spread/runtime errors and prevent silent no-op merges.
  • Simplify esbuild watcher cleanup by switching from .map().flat() to .flatMap(... ?? []) when contexts may be missing.
  • Remove a fragile non-null assertion in log source grouping by using a ?? [] fallback, and add tests for the webhook reducer behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/app/src/cli/services/dev/app-events/app-watcher-esbuild.ts Makes deleteContexts robust when an extension has no contexts entry by using flatMap with a safe fallback.
packages/app/src/cli/services/app-logs/sources.ts Replaces Map.get()! with ?? [] to avoid potential runtime exceptions if the has()/set() logic changes.
packages/app/src/cli/models/extensions/specifications/transform/app_config_webhook.ts Adds Array.isArray guards and initializes missing arrays before pushing to avoid spread-related runtime errors and data loss.
packages/app/src/cli/models/extensions/specifications/transform/app_config_webhook.test.ts Adds tests covering property-based merging and initialization behavior in reduceWebhooks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@durga256 durga256 marked this pull request as ready for review April 13, 2026 21:02
@durga256 durga256 closed this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants