fix: prevent fatal crash when startServer() called with missing hosts#322
Merged
Conversation
startServer() is a public export but had no validation — calling it with incomplete config (e.g. missing hosts field) caused: TypeError: Cannot read properties of undefined (reading 'map') This was LOREAI-GATEWAY-F, a fatal unhandled crash in production. Two co-contributing fixes: 1. Add defensive defaults in startServer(): if config.hosts is missing, default to ["127.0.0.1"] with a warning. Also default port if missing. 2. Fix hand-written dist/index.d.cts type declarations which declared host?: string (singular, optional) instead of hosts: string[] (plural, required), made startServer config param optional, and omitted key exports (startGateway, probeGateway, readPortFile, GatewayHandle). The wrong types actively misled npm consumers into calling startServer with incomplete config.
- Remove handleRequest from .d.cts (internal API with wrong signature) - Export StartOptions type from index.ts (was declared in .d.cts but missing) - Fix resetPipelineState return type: void -> Promise<void> - Guard against config itself being undefined/null - Guard against NaN port values with Number.isFinite()
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
Fixes LOREAI-GATEWAY-F — a fatal unhandled
TypeError: Cannot read properties of undefined (reading 'map')crash whenstartServer()is called with incomplete config (missinghostsfield).startServer(): ifconfig.hostsis missing/empty, default to["127.0.0.1"]with a warning; also defaultportif missingdist/index.d.ctstype declarations which declaredhost?: string(singular, optional) instead ofhosts: string[](plural, required), madestartServerconfig optional, and omitted key exports (startGateway,probeGateway,readPortFile,GatewayHandle,StartOptions,DEFAULT_PORTS,DEFAULT_PORT)Root Cause
The published
.d.ctsactively misled npm consumers into callingstartServer()directly with incomplete config. The types declaredhost?: stringinstead ofhosts: string[], madeconfigoptional, and omitted the safe entry pointstartGateway()entirely.Files Changed
packages/gateway/src/server.tshosts/portat top ofstartServer()packages/gateway/script/bundle.ts.d.ctstype declarations matching actual source exportsVerification
bun run typecheck— all 4 packages passbun test— all 1445 tests passbun run bundle— regenerateddist/index.d.ctsverified correctnode -e "require('./dist/index.cjs').startServer({})"warns and defaults instead of crashing