Azure / Azure/azure-rest-api-specs

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

Open
#29,925 2 comments 0 reactions 0 assignees View on GitHub
bug data-plane
Dominant language
TypeSpec
Stars
3.1k
Forks
5.9k
Avg merge
2d 22h
Merged PRs (30d)
444

Description

### 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](https://github.com/Azure/autorest.java/pull/2854): but the customization doesn't work.

I am getting the following error:
```bash
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. (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:
```yaml
"@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`](https://github.com/danielszaniszlo/azure-sdk-for-java/blob/daszanis/feature/sdk-for-health-deid/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
```bash
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. (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

Contributor guide

Open the contributing guide

Research direction

Start with eng/scripts/TypeSpec-Generate-Sdk.ps1 and the @azure-tools/typespec-java postprocessing path, then inspect the tsp config and customization/src/main/java/HealthDeidentificationSdkCustomization.java. Reproduce generation with and without customization in the azure-health-deidentification project and compare the failure around the closed pipe. Done means the SDK generates successfully with customization enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, powershell
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.