belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.43k stars 99 forks source link

More reliable extensions #995

Closed belav closed 7 months ago

belav commented 1 year ago

Based on the problem with #989, it makes sense to add better error handling. The code in csharpier probably needs to use a try/catch around the call to format a file. If the work to get GRPC working is done, it would be easier to report the failure back to the extension.

Maybe it is also possible to detect the crashing/hung csharpier process better on the extension side. I can re-introduce the problem and try to come up with a better way to deal with a similar situation in the future.

  1. Ignore in rider C:\Users\bela\AppData\Local\Temp\SourceGeneratedDocuments\F4DCBEE912DC99E14C52B9BC\CSharpier.Tests.Generators\CSharpier.Tests.Generators.FormattingTestsGenerator
  2. Add logging on the csharpier end
  3. Make sure extensions don't retry a hung csharpier indefinitely - may be done in all but VS
  4. VS does not have the better validation/notification yet
  5. VSCode does not link to read more troubleshooting
  6. Look at #1048 a bit, it seems that if one IDE is using csharpier, then another one can't delete it. But why would it delete it if it can be run?
  7. Can we read the error output of trying to install csharpier? the failure in #1050 seems to be a problem installing csharpier
belav commented 1 year ago

Some exceptions I saw around the time Rider finally hung for me

2023-11-18 10:28:21,937 [   8786]   WARN - #c.i.c.CSharpierLogger - Exception while running 'dotnet csharpier --version' in C:\Users\bela\AppData\Local\CSharpier\0.26.0
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "output" is null
    at com.intellij.csharpier.CustomPathInstaller.ensureVersionInstalled(CustomPathInstaller.java:30)
    at com.intellij.csharpier.CSharpierProcessProvider.setupCSharpierProcess(CSharpierProcessProvider.java:203)
    at com.intellij.csharpier.CSharpierProcessProvider.findAndWarmProcess(CSharpierProcessProvider.java:92)
    at com.intellij.csharpier.CSharpierProcessProvider.<init>(CSharpierProcessProvider.java:45)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)

2023-11-18 10:28:21,930 [   8779] SEVERE - #c.i.c.CSharpierLogger - Cannot run program "C:\Users\bela\AppData\Local\CSharpier\0.26.0\dotnet-csharpier" (in directory "C:\Users\bela\AppData\Local\CSharpier\0.26.0"): CreateProcess error=2, The system cannot find the file specified
java.lang.Throwable: Cannot run program "C:\Users\bela\AppData\Local\CSharpier\0.26.0\dotnet-csharpier" (in directory "C:\Users\bela\AppData\Local\CSharpier\0.26.0"): CreateProcess error=2, The system cannot find the file specified
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:370)
    at com.intellij.csharpier.ProcessHelper.ExecuteCommand(ProcessHelper.java:53)
    at com.intellij.csharpier.CustomPathInstaller.ensureVersionInstalled(CustomPathInstaller.java:26)
    at com.intellij.csharpier.CSharpierProcessProvider.setupCSharpierProcess(CSharpierProcessProvider.java:203)
    at com.intellij.csharpier.CSharpierProcessProvider.findAndWarmProcess(CSharpierProcessProvider.java:92)
    at com.intellij.csharpier.CSharpierProcessProvider.<init>(CSharpierProcessProvider.java:45)
markusmeder commented 11 months ago

I also experience the issue with "System.UnauthorizedAccessException: Access to the path 'CSharpier.dll' is denied.".

When I open the first solution csharpier works fine, but i get this error as soon as I open a second solution. Formatting in the first solution still works fine.

I use visual studio 17.8.3 on windows and csharpier 0.26.5 installed globally.