microsoft / microsoft/typespec

csharp CodeGen should provide clear message for self-service trouble shooting

Open
#5,508 7 comments 0 reactions 1 assignee Claimed by @JoshLove-msft View on GitHub
emitter:client:csharp
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Clear and concise description of the problem

We need to empower our customers both internal and external to easily trouble shooting and fix spec issues that would block the CodeGen.
If certain TypeSpec features or patterns are not supported by CodeGen, we should clearly point it out and suggest them to update the spec with the features we supported for CodeGen.

Today, csharp CodeGen just returned a big call-stack like below which could not help for self-service resolving the problem.

```
Unhandled exception. System.NotSupportedException: BinaryData
at AutoRest.CSharp.Generation.Types.CSharpType.GetElementType() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Generat
ion\Types\CSharpType.cs:line 336
at AutoRest.CSharp.Generation.Types.CSharpType.get_ElementType() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Genera
tion\Types\CSharpType.cs:line 224
at AutoRest.CSharp.Output.Builders.SerializationBuilder.BuildJsonSerialization(InputType inputType, CSharpType valueType, Boolean is
CollectionElement, SerializationFormat serializationFormat) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Builder
s\SerializationBuilder.cs:line 162
at AutoRest.CSharp.Output.Builders.SerializationBuilder.BuildJsonSerialization(InputType inputType, CSharpType valueType, Boolean is
CollectionElement) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Builders\SerializationBuilder.cs:line 172
at AutoRest.CSharp.Output.Builders.SerializationBuilder.CreateJsonPropertySerializationFromInputModelProperty(SerializableObjectType
objectType, ObjectTypeProperty property, TypeFactory typeFactory) in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\
Builders\SerializationBuilder.cs:line 291
at AutoRest.CSharp.Output.Builders.SerializationBuilder.<>c__DisplayClass16_0.b__0(ObjectTypeProperty p)
in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Builders\SerializationBuilder.cs:line 441
at AutoRest.CSharp.Output.Builders.SerializationBuilder.GetPropertySerializationsFromBag[T](PropertyBag`1 propertyBag, Func`2 jsonPr
opertySerializationFactory)+MoveNext() in D:\a\_work\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Builders\SerializationBuilde
r.cs:line 331
```

**Expected behavior:**

I suggest we could improve the following areas:

1. Leverage TypeSpec diagnostics APIs to report the errors and provide more context so that users could easily identify the TypeSpec source that cause the error..
2. Provide a clear message for the unsupported scenarios and ideally provide some suggestions on how to fix.

**workstream this request is associated with**

This is related to the TypeSpec E2E scenario and ensure service team/customer to self service trouble shooting the problem

**stakeholders**

@lmazuel / @lirenhe

**priority and timeline.**

I suggest we should provide a better experience for self-service trouble shooting as part of the TypeSpec GA.

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Read the [docs](https://typespec.io/docs/).
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.