Fix spread syntax runtime error on non-iterable values#7271
Closed
Fix spread syntax runtime error on non-iterable values#7271
Conversation
f77632f to
a95c924
Compare
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>
a95c924 to
0a614df
Compare
Contributor
There was a problem hiding this comment.
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
reduceWebhooksmerging logic usingArray.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
!non-null assertions and truthy checks withArray.isArrayguards inreduceWebhookswebhook config transform — also fixes a silent data-loss bug where topics were dropped whenexistingSubscription[property]was undefined (the old?.pushwould silently no-op).map().flat()with.flatMap(... ?? [])in esbuild watcherdeleteContextsto handle missing context entriesMap.get()!pattern in app-logssourcesby using?? []fallbackreduceWebhooksproperty-branch merging, covering the??= []initialization caseWhy
Observe reports a "Spread syntax requires ...iterable[Symbol.iterator] to be a function" runtime error in the
appslice. The strongest candidate isreduceWebhooksin the webhook config transform, where subscription data is spread using!non-null assertions — if the data has unexpected shape, the spread throws. TheMap.get()!in sources.ts is the only such pattern in the codebase and is fragile if thehas()guard above is ever refactored away. The esbuild watcher usesflatMapas 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 passpnpm vitest run packages/app/src/cli/services/app-logs/sources.test.ts— 1 test passes