-
Notifications
You must be signed in to change notification settings - Fork 77
Fix TypeScript emitter crash when processing binary responses with application/cose content type #3429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: MaryGao <[email protected]>
Co-authored-by: MaryGao <[email protected]>
Co-authored-by: MaryGao <[email protected]>
Co-authored-by: MaryGao <[email protected]>
|
Co-authored-by: MaryGao <[email protected]>
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. |
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:
getDeserializePrivateFunction
tried to accessresponse.type.__raw
without checking if it existsgetEffectiveModelFromType
attempted to read thekind
property 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:
getDeserializePrivateFunction
to safely accessresponse.type.__raw
with proper fallback logicgetEffectiveModelFromType
,isByteOrByteUnion
,isBytesType
, andisBytesUnion
functionsTesting
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/cose
content-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.