Azure / azure-rest-api-specs

The source for REST API specifications for Microsoft Azure.
MIT License
2.68k stars 5.1k forks source link

[BUG] customization-class doesn't work when generating java SDK #29925

Open danielszaniszlo opened 3 months ago

danielszaniszlo commented 3 months ago

API Spec link

https://github.com/Azure/azure-rest-api-specs/tree/main/specification/healthdataaiservices/HealthDataAIServices.DeidServices

API Spec version

latest

Describe the bug

I need to override the generated java SDK code because of an Autorest bug: but the customization doesn't work.

I am getting the following error:

Exception in thread "main" java.lang.RuntimeException: Failed to complete postprocessing.                            ]
        at com.azure.autorest.postprocessor.Postprocessor.postProcess(Postprocessor.java:111)
        at com.azure.typespec.Main.handleDPG(Main.java:169)
        at com.azure.typespec.Main.main(Main.java:116)
Caused by: java.lang.RuntimeException: Unable to complete customization
        at com.azure.autorest.postprocessor.Postprocessor.postProcess(Postprocessor.java:104)
        ... 2 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
        at com.azure.autorest.customization.Customization.run(Customization.java:52)
        at com.azure.autorest.postprocessor.Postprocessor.postProcess(Postprocessor.java:101)
        ... 2 more
Caused by: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
        at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:352)
        at com.azure.autorest.extension.base.jsonrpc.Connection.requestWithSerializedObject(Connection.java:519)
        at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.sendRequest(EclipseLanguageClient.java:219)
        at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.initialize(EclipseLanguageClient.java:124)
        at com.azure.autorest.customization.Customization.run(Customization.java:47)
        ... 3 more
        Suppressed: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
                at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.close(EclipseLanguageClient.java:213)
                at com.azure.autorest.customization.Customization.run(Customization.java:45)
                ... 3 more
        Caused by: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
                at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:352)
                at com.azure.autorest.extension.base.jsonrpc.Connection.request(Connection.java:465)
                at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.close(EclipseLanguageClient.java:208)
                ... 4 more
        Caused by: java.io.IOException: The pipe is being closed
                at java.base/java.io.FileOutputStream.writeBytes(Native Method)
                at java.base/java.io.FileOutputStream.write(FileOutputStream.java:367)
                at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:125)
                at java.base/java.io.BufferedOutputStream.implFlush(BufferedOutputStream.java:252)
                at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:240)
                at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:350)
                ... 6 more
Caused by: java.io.IOException: The pipe is being closed
        at java.base/java.io.FileOutputStream.writeBytes(Native Method)
        at java.base/java.io.FileOutputStream.write(FileOutputStream.java:367)
        at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:125)
        at java.base/java.io.BufferedOutputStream.implFlush(BufferedOutputStream.java:252)
        at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:240)
        at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:350)
        ... 7 more
Emitter "@azure-tools/typespec-java" crashed! This is a bug.
Please file an issue at https://github.com/Azure/autorest.java/issues

Error: JAR ended with code '1'.
    at ChildProcess.<anonymous> (file:///C:/Users/daszanis/WORK/REPO/sdk-repos/sdk-repos/azure-sdk-for-java/sdk/healthdataaiservices/azure-health-deidentification/TempTypeSpecFiles/HealthDataAIServices.DeidServices/node_modules/@azure-tools/typespec-java/dist/src/emitter.js:123:37)
    at ChildProcess.emit (node:events:517:28)
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)

--------------------------------------------------
Library Version                0.18.1
TypeSpec Compiler Version      0.58.0
Write-Error: C:\Users\daszanis\WORK\REPO\sdk-repos\azure-rest-api-specs\eng\scripts\TypeSpec-Generate-Sdk.ps1:92
Line |
  92 |      . $commonScript -TypeSpecProjectDirectory $TypeSpecProjectDirecto …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Failed to generate sdk project at
     | C:\Users\daszanis\WORK\REPO\sdk-repos\sdk-repos\azure-sdk-for-java\sdk\healthdataaiservices\azure-health-deidentification

This is my related tsp config:

"@azure-tools/typespec-java":
    package-dir: "azure-health-deidentification"
    customization-class: "customization/src/main/java/HealthDeidentificationSdkCustomization.java"
    namespace: "com.azure.health.deidentification"
    flavor: azure

My customization class is at sdk/healthdataaiservices/azure-health-deidentification/customization/src/main/java/HealthDeidentificationSdkCustomization.java

Without the customization-class SDK generates without error.

Expected behavior

The SDK generates successfully with customization.

Actual behavior

I get the error message

Exception in thread "main" java.lang.RuntimeException: Failed to complete postprocessing.                            ]
        at com.azure.autorest.postprocessor.Postprocessor.postProcess(Postprocessor.java:111)
        at com.azure.typespec.Main.handleDPG(Main.java:169)
        at com.azure.typespec.Main.main(Main.java:116)
Caused by: java.lang.RuntimeException: Unable to complete customization
        at com.azure.autorest.postprocessor.Postprocessor.postProcess(Postprocessor.java:104)
        ... 2 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
        at com.azure.autorest.customization.Customization.run(Customization.java:52)
        at com.azure.autorest.postprocessor.Postprocessor.postProcess(Postprocessor.java:101)
        ... 2 more
Caused by: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
        at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:352)
        at com.azure.autorest.extension.base.jsonrpc.Connection.requestWithSerializedObject(Connection.java:519)
        at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.sendRequest(EclipseLanguageClient.java:219)
        at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.initialize(EclipseLanguageClient.java:124)
        at com.azure.autorest.customization.Customization.run(Customization.java:47)
        ... 3 more
        Suppressed: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
                at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.close(EclipseLanguageClient.java:213)
                at com.azure.autorest.customization.Customization.run(Customization.java:45)
                ... 3 more
        Caused by: java.lang.RuntimeException: java.io.IOException: The pipe is being closed
                at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:352)
                at com.azure.autorest.extension.base.jsonrpc.Connection.request(Connection.java:465)
                at com.azure.autorest.customization.implementation.ls.EclipseLanguageClient.close(EclipseLanguageClient.java:208)
                ... 4 more
        Caused by: java.io.IOException: The pipe is being closed
                at java.base/java.io.FileOutputStream.writeBytes(Native Method)
                at java.base/java.io.FileOutputStream.write(FileOutputStream.java:367)
                at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:125)
                at java.base/java.io.BufferedOutputStream.implFlush(BufferedOutputStream.java:252)
                at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:240)
                at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:350)
                ... 6 more
Caused by: java.io.IOException: The pipe is being closed
        at java.base/java.io.FileOutputStream.writeBytes(Native Method)
        at java.base/java.io.FileOutputStream.write(FileOutputStream.java:367)
        at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:125)
        at java.base/java.io.BufferedOutputStream.implFlush(BufferedOutputStream.java:252)
        at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:240)
        at com.azure.autorest.extension.base.jsonrpc.Connection.send(Connection.java:350)
        ... 7 more
Emitter "@azure-tools/typespec-java" crashed! This is a bug.
Please file an issue at https://github.com/Azure/autorest.java/issues

Error: JAR ended with code '1'.
    at ChildProcess.<anonymous> (file:///C:/Users/daszanis/WORK/REPO/sdk-repos/sdk-repos/azure-sdk-for-java/sdk/healthdataaiservices/azure-health-deidentification/TempTypeSpecFiles/HealthDataAIServices.DeidServices/node_modules/@azure-tools/typespec-java/dist/src/emitter.js:123:37)
    at ChildProcess.emit (node:events:517:28)
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)

--------------------------------------------------
Library Version                0.18.1
TypeSpec Compiler Version      0.58.0
Write-Error: C:\Users\daszanis\WORK\REPO\sdk-repos\azure-rest-api-specs\eng\scripts\TypeSpec-Generate-Sdk.ps1:92
Line |
  92 |      . $commonScript -TypeSpecProjectDirectory $TypeSpecProjectDirecto …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Failed to generate sdk project at
     | C:\Users\daszanis\WORK\REPO\sdk-repos\sdk-repos\azure-sdk-for-java\sdk\healthdataaiservices\azure-health-deidentification

Reproduction Steps

run TypeSpec-Generate-Sdk.ps1 pointing to the azure-sdk-for-java repository

Environment

Windows 11 Powershell Version 7

raych1 commented 3 months ago

+@weidongxu-microsoft can you assist on this issue?

weidongxu-microsoft commented 3 months ago

see https://github.com/Azure/azure-sdk-for-java/wiki/TypeSpec-Java-Quickstart#customization

⚠️ At present, customization may fail due to certain caching problem. Deleting the "autorest-java-language-server" folder under system temporary folder (typically \Users\\AppData\Local\Temp on Windows) may solve the problem.