Fix TypeScript emitter crash when processing binary responses with application/cose content type#3429
Fix TypeScript emitter crash when processing binary responses with application/cose content type#3429
Conversation
Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
|
Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
I've completed both requests:
The changes are in commit 7a0da3b and include:
All tests pass, confirming the generated code compiles successfully and handles binary COSE responses correctly. |
|
Please add a test case in spector. |
Issue here: microsoft/typespec#8405. |
|
duplicate with #3580 |
The TypeScript emitter was crashing with
TypeError: Cannot read properties of undefined (reading 'kind')when processing binary responses that use "application/cose" content type with@bodyRoot body: bytes;pattern, as seen in the @azure-rest/codetransparency service specification.Root Cause
The crash occurred in the binary payload detection pipeline when:
getDeserializePrivateFunctiontried to accessresponse.type.__rawwithout checking if it existsgetEffectiveModelFromTypeattempted to read thekindproperty on undefined/null type objectsisByteOrByteUnion,isBytesType,isBytesUnion) didn't handle null/undefined inputs gracefullySolution
Added comprehensive null/undefined checks throughout the binary payload detection pipeline:
getDeserializePrivateFunctionto safely accessresponse.type.__rawwith proper fallback logicgetEffectiveModelFromType,isByteOrByteUnion,isBytesType, andisBytesUnionfunctionsTesting
Before/After
Before: TypeScript emitter crashed with stack trace showing
Cannot read properties of undefined (reading 'kind')After: TypeScript emitter successfully processes binary COSE specifications and generates correct TypeScript code with:
Promise<Uint8Array>application/cosecontent-type and accept headersFixes #3425.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.