fix: handle undefined functionTypeMapping in all protocol generators#356
Merged
jonaslagoni merged 1 commit intomainfrom Apr 13, 2026
Merged
fix: handle undefined functionTypeMapping in all protocol generators#356jonaslagoni merged 1 commit intomainfrom
jonaslagoni merged 1 commit intomainfrom
Conversation
✅ Deploy Preview for the-codegen-project canceled.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
|
🎉 This PR is included in version 0.70.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
Fix a crash bug where all protocol generators (NATS, Kafka, MQTT, AMQP, WebSocket, EventSource, HTTP) throw
Cannot read properties of undefined (reading 'channel_id')whengenerator.functionTypeMappingisundefinedinstead of the expected empty object{}.Type of Change
Changes Made
New Files
test/codegen/generators/typescript/channels/protocols/functionTypeMapping.spec.ts- Unit tests verifying all 7 protocol generators handle undefinedfunctionTypeMappinggracefullyModified Files
src/codegen/generators/typescript/channels/protocols/nats/index.ts- Added optional chaining at lines 115, 328src/codegen/generators/typescript/channels/protocols/kafka/index.ts- Added optional chaining at lines 100, 185src/codegen/generators/typescript/channels/protocols/mqtt/index.ts- Added optional chaining at lines 98, 160src/codegen/generators/typescript/channels/protocols/amqp/index.ts- Added optional chaining at lines 99, 195src/codegen/generators/typescript/channels/protocols/websocket/index.ts- Added optional chaining at lines 109, 211src/codegen/generators/typescript/channels/protocols/eventsource/index.ts- Added optional chaining at lines 100, 191src/codegen/generators/typescript/channels/protocols/http/index.ts- Added optional chaining at line 113Key Implementation Details
Root Cause
The bug occurs because:
functionTypeMappingwith.optional().default({})functionTypeMapping: undefinedis explicitly set (not missing), spread operators preserveundefinedgenerator.functionTypeMapping[channel.id()]without checking iffunctionTypeMappingexistsFix
Added optional chaining (
?.) at all 13 access points across 7 protocol generators:Testing
Unit Tests (TDD)
✅ Tests written BEFORE implementation and verified to FAIL:
✅ Tests PASS after implementation:
Full Test Suite
✅ All unit tests pass:
npm run testBuild
✅ Build succeeds:
npm run buildLint
✅ Lint passes:
npm run lintRuntime Generate
✅ Runtime code generates successfully:
npm run runtime:typescript:generateBreaking Changes
None - This is a purely additive defensive fix using optional chaining. Existing behavior is unchanged for valid configurations.
Checklist
Verification
After implementation, verified no unguarded access remains:
🤖 Generated with Claude Code
Note
Low Risk
Low risk: small defensive change (optional chaining) in TypeScript channel codegen; main risk is minor behavior change in how default function-type filtering is applied when the mapping is missing/undefined.
Overview
Prevents crashes in the TypeScript channels codegen when
generator.functionTypeMappingis explicitlyundefinedby switching all protocol generators (AMQP, EventSource, HTTP client, Kafka, MQTT, NATS, WebSocket) to use optional-chained lookups (generator.functionTypeMapping?.[channel.id()]).Adds a Jest regression test that runs
generateTypeScriptChannelsacross each protocol (and a combined run) withfunctionTypeMappingforced toundefined, asserting generation completes without throwing.Reviewed by Cursor Bugbot for commit 7984353. Bugbot is set up for automated code reviews on this repo. Configure here.