Skip to content
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

Can't generate contoso project with typespec-csharp #4827

Open
catalinaperalta opened this issue Jun 18, 2024 · 7 comments
Open

Can't generate contoso project with typespec-csharp #4827

catalinaperalta opened this issue Jun 18, 2024 · 7 comments
Assignees
Labels
DPG/RLC v2.1 Post Gallium work DPG needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. v3 Version 3 of AutoRest C# generator.

Comments

@catalinaperalta
Copy link
Member

Describe the issue or request
Someone from the API mgmt team tried to run tsp-client init -c https://github.com/Azure/azure-rest-api-specs/blob/431eb865a581da2cd7b9e953ae52cb146f31c2a6/specification/contosowidgetmanager/Contoso.WidgetManager/tspconfig.yaml in the azure-sdk-for-net repo and ran into the following emitter issue:

C:\Users\caperal\repos\azure-sdk-for-net> tsp-client init -c https://github.com/Azure/azure-rest-api-specs/blob/431eb865a581da2cd7b9e953ae52cb146f31c2a6/specification/contosowidgetmanager/Contoso.WidgetManager/tspconfig.yaml
Use output directory 'C:/Users/caperal/repos/azure-sdk-for-net'? (y/n) 
Using output directory 'C:/Users/caperal/repos/azure-sdk-for-net'

888                                      888 d8b                   888
888                                      888 Y8P                   888
888                                      888                       888
888888 .d8888b  88888b.          .d8888b 888 888  .d88b.  88888b.  888888
888    88K      888 "88b        d88P"    888 888 d8P  Y8b 888 "88b 888
888    "Y8888b. 888  888 888888 888      888 888 88888888 888  888 888
Y88b.       X88 888 d88P        Y88b.    888 888 Y8b.     888  888 Y88b.
 "Y888  88888P' 88888P"          "Y8888P 888 888  "Y8888  888  888  "Y888
                888
                888
                888

tsp-client version: 0.8.1
Found emitter package @azure-tools/typespec-csharp
SDK initialized in C:/Users/caperal/repos/azure-sdk-for-net/sdk/contosowidgetmanager/Azure.Template.Contoso
Processing additional directory: specification/contosowidgetmanager/Contoso.WidgetManager.Shared
Syncing additional directory: specification/contosowidgetmanager/Contoso.WidgetManager.Shared
Found emitter package @azure-tools/typespec-csharp
Installing dependencies from npm...

added 85 packages, and audited 86 packages in 3s

12 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
Resolved path: C:/Users/caperal/repos/azure-sdk-for-net/sdk/contosowidgetmanager/Azure.Template.Contoso/TempTypeSpecFiles/Contoso.WidgetManager/node_modules/@typespec/compiler
Compiling tsp using @azure-tools/typespec-csharp...
Unhandled exception. System.Exception: Unknown type
   at AutoRest.CSharp.Generation.Types.TypeFactory.CreateType(InputType inputType) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Generation\Types\TypeFactory.cs:line 92
   at AutoRest.CSharp.Output.Models.OperationMethodChainBuilder.GetLongRunningResultRetrievalMethod(OperationLongRunning longRunning) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\Output\OperationMethodChainBuilder.cs:line 174
   at AutoRest.CSharp.Output.Models.OperationMethodChainBuilder.BuildOperationMethodChain() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\Output\OperationMethodChainBuilder.cs:line 115
   at AutoRest.CSharp.Output.Models.LowLevelClient.BuildMethods(LowLevelClient client, TypeFactory typeFactory, IEnumerable`1 operations, ClientFields fields, String namespaceName, String clientName, SourceInputModel sourceInputModel)+MoveNext() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\Output\LowLevelClient.cs:line 131
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at AutoRest.CSharp.Output.Models.LowLevelClient.get_AllClientMethods() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\Output\LowLevelClient.cs:line 95
   at AutoRest.CSharp.Output.Models.LowLevelClient.get_ClientMethods() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\Output\LowLevelClient.cs:line 98
   at AutoRest.CSharp.LowLevel.Output.Samples.DpgClientSampleProvider..ctor(String defaultNamespace, LowLevelClient client, SourceInputModel sourceInputModel) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\Output\Samples\DpgClientSampleProvider.cs:line 30
   at AutoRest.CSharp.Output.Models.Types.DpgOutputLibrary.EnsureDpgSampleProviders() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\AutoRest\DpgOutputLibrary.cs:line 110
   at AutoRest.CSharp.Output.Models.Types.DpgOutputLibrary.get_DpgClientSampleProviders() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\AutoRest\DpgOutputLibrary.cs:line 98
   at AutoRest.CSharp.Output.Models.Types.DpgOutputLibrary.GetSampleForClient(LowLevelClient client) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\AutoRest\DpgOutputLibrary.cs:line 119
   at AutoRest.CSharp.AutoRest.Plugins.LowLevelTarget.ExecuteAsync(GeneratedCodeWorkspace project, InputNamespace inputNamespace, SourceInputModel sourceInputModel, Boolean isTspInput) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\LowLevel\AutoRest\LowLevelTarget.cs:line 43
   at AutoRest.CSharp.AutoRest.Plugins.CSharpGen.ExecuteAsync(InputNamespace rootNamespace) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\AutoRest\Plugins\CSharpGen.cs:line 104
   at AutoRest.CSharp.AutoRest.Communication.StandaloneGeneratorRunner.RunAsync(CommandLineOptions options) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\AutoRest\Communication\StandaloneGeneratorRunner.cs:line 51
   at AutoRest.CSharp.Program.Run(CommandLineOptions options) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 47
   at AutoRest.CSharp.Program.<>c.<<Main>b__2_0>d.MoveNext() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 29
--- End of stack trace from previous location ---
   at AutoRest.CSharp.Program.Main(String[] args) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Program.cs:line 26     
   at AutoRest.CSharp.Program.<Main>(String[] args)
ExternalError: Emitter "@azure-tools/typespec-csharp" crashed! This is a bug.
Please file an issue at https://github.com/Azure/autorest.csharp/issues

Error: Command failed: dotnet --roll-forward Major C:/Users/caperal/repos/azure-sdk-for-net/sdk/contosowidgetmanager/Azure.Template.Contoso/TempTypeSpecFiles/Contoso.WidgetManager/node_modules/@autorest/csharp/AutoRest.CSharp.dll --project-path C:/Users/caperal/repos/azure-sdk-for-net/sdk/contosowidgetmanager/Azure.Template.Contoso --new-project  --clear-output-folder true      
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at Object.$onEmit [as emitFunction] (file:///C:/Users/caperal/repos/azure-sdk-for-net/sdk/contosowidgetmanager/Azure.Template.Contoso/TempTypeSpecFiles/Contoso.WidgetManager/node_modules/@azure-tools/typespec-csharp/dist/src/emitter.js:106:21)       
    at async runEmitter (file:///C:/Users/caperal/repos/azure-sdk-for-net/sdk/contosowidgetmanager/Azure.Template.Contoso/TempTypeSpecFiles/Contoso.WidgetManager/node_modules/@typespec/compiler/dist/src/core/program.js:555:13)
    at async compile (file:///C:/Users/caperal/repos/azure-sdk-for-net/sdk/contosowidgetmanager/Azure.Template.Contoso/TempTypeSpecFiles/Contoso.WidgetManager/node_modules/@typespec/compiler/dist/src/core/program.js:237:9)
    at async compileTsp (file:///C:/Users/caperal/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/typespec.js:76:21)
    at async generate (file:///C:/Users/caperal/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:204:5)
    at async main (file:///C:/Users/caperal/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:277:17)

--------------------------------------------------
Library Version                0.2.0-beta.20240614.3
TypeSpec Compiler Version      0.56.0
--------------------------------------------------

Describe your ideas for solutions
I would expect the contoso project in the azure-rest-api-specs repo to be able to be generated with the csharp emitter.

Add labels
As appropriate, select a label to describe how hard the issue is to work
around or how hard it would be to do without a particular feature that
could help make it easier. These labels start with "workaround".

Also select a label that describes how many instances of the workaround
you would have to do without the bug being fixed or feature implemented.
These labels start with "instances".

These labels will help priority bug fixes and feature requests.

If this bug or feature request is for older versions of autorest, please
remove the v3 label and add the v2 label as appropriate.

@catalinaperalta catalinaperalta added the v3 Version 3 of AutoRest C# generator. label Jun 18, 2024
@catalinaperalta
Copy link
Member Author

cc @lirenhe @chunyu3

@chunyu3 chunyu3 self-assigned this Jun 18, 2024
@chunyu3
Copy link
Member

chunyu3 commented Jun 18, 2024

hello @catalinaperalta The error show that there is a type which is not supported. Would you please provide the spec used for us to investigate? thanks

@catalinaperalta
Copy link
Member Author

@chunyu3
Copy link
Member

chunyu3 commented Jul 4, 2024

The root cause is that the ReturnType of LRO operation is null but the ResultPath is not null. @archerzz would you please help on this? thanks

@archerzz
Copy link
Member

The root cause is the @pollingOperation: https://github.com/Azure/azure-rest-api-specs/blob/934f8b595b6aba70096c6fd19089c3986b344c0c/specification/contosowidgetmanager/Contoso.WidgetManager/main.tsp#L53C29-L53C53

@pollingOperation(Widgets.getWidgetOperationStatus)

Widgets.getWidgetOperationStatus is defined as a polling with return value: https://github.com/Azure/azure-rest-api-specs/blob/934f8b595b6aba70096c6fd19089c3986b344c0c/specification/contosowidgetmanager/Contoso.WidgetManager/main.tsp#L46

getWidgetOperationStatus is GetResourceOperationStatus<WidgetSuite>;

So, the LroMetadata contains ResultPath (because you have a resource polling), but no ReturnType (because its delete).

@archerzz
Copy link
Member

@catalinaperalta I created a PR to fix the problematic spec: Azure/azure-rest-api-specs#30012

archerzz added a commit to archerzz/typespec-azure that referenced this issue Jul 30, 2024
This is found during investigation of Azure/autorest.csharp#4827
Normally an lro delete status operation should not return content at the end, so when defining lro deelte operation, it should use a special status operation.
@chunyu3 chunyu3 added the DPG/RLC v2.1 Post Gallium work label Aug 27, 2024
archerzz added a commit to archerzz/typespec-azure that referenced this issue Aug 28, 2024
Currently in the offical guide, the same polling operation is shared by all lro operations, which could cause problems for some emitters since the lro metadata contains value which doesn't fit for lro delete. See Azure/autorest.csharp#4827
This commit will create a separate polling operation which fits lro delete. The same definition is already available in https://github.com/Azure/typespec-azure/blob/955fc9534c2f7153d45c9fbe5743baa0c104d803/packages/samples/specs/data-plane/trait-versioning/main.tsp#L72-L77
@chunyu3 chunyu3 added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Sep 3, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the no-recent-activity There has been no recent activity on this issue. label Sep 10, 2024
Copy link
Contributor

Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DPG/RLC v2.1 Post Gallium work DPG needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. v3 Version 3 of AutoRest C# generator.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants