Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
14 stars 40 forks source link

[Bug]: azure-tools/typespec-autorest crashes: Cannot read properties of undefined (reading 'stateMap' #1292

Closed richardpark-msft closed 2 months ago

richardpark-msft commented 2 months ago

Describe the bug

azure-tools/typespec-autorest crashes when trying to build out a commit from the azure-rest-api-specs repo for OpenAI.

Stack trace (I used instead of my local path, but it's otherwise unchanged):

Emitter "@azure-tools/typespec-autorest" crashed! This is a bug.
Please file an issue at https://github.com/Azure/typespec-azure/issues

TypeError: Cannot read properties of undefined (reading 'stateMap')
    at getScopedDecoratorData (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-client-generator-core/dist/src/decorators.js:13:36)
    at shouldFlattenProperty (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-client-generator-core/dist/src/decorators.js:732:12)
    at applyIntrinsicDecorators (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-autorest/dist/src/openapi.js:1515:13)
    at getOpenAPI2Parameter (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-autorest/dist/src/openapi.js:879:27)
    at resolveHost (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-autorest/dist/src/openapi.js:166:27)
    at getOpenAPIForService (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-autorest/dist/src/openapi.js:45:12)
    at getAllServicesAtAllVersions (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-autorest/dist/src/emit.js:101:38)
    at emitAllServiceAtAllVersions (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-autorest/dist/src/emit.js:113:28)
    at Object.$onEmit [as emitFunction] (<root>/sdk/ai/azopenai/testdata/node_modules/@azure-tools/typespec-autorest/dist/src/emit.js:16:11)
    at runEmitter (<root>/sdk/ai/azopenai/testdata/node_modules/@typespec/compiler/dist/src/core/program.js:452:27)

Package.json dependencies:

  "dependencies": {
    "@azure-tools/typespec-autorest": "0.44.0",
    "@azure-tools/typespec-azure-core": "0.44.0",
    "@typespec/compiler": "0.58.0",
    "@typespec/openapi3": "0.58.0"
  }

Reproduction

I uploaded a standalone version of this project here: https://github.com/richardpark-msft/openai-gen-bug

I apologize that it's not small, but it does demonstrate the problem readily. I added a 'repro' command script, so you can just do:

npm run repro

And you'll get the error.

Checklist

richardpark-msft commented 2 months ago

@tadelesh, assigned it to you (@jhendrixMSFT thought you'd make sense as the owner).

tadelesh commented 2 months ago

please upgrade @azure-tools/typespec-autorest to 0.44.1.