domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.25k stars 1.31k forks source link

cli errors do not go to stderror stream #2476

Closed esmadau closed 6 months ago

esmadau commented 2 years ago

swashbuckle version: 6.1.4 and 6.4.0

In a case where .NET version expected to be able to use dotnet swagger is not found, the output seems like it should be an error, but instead is just informational. This is causing issues when trying to use this in processes where an error is expected to fail the task appropriately, whether the failure occurs on writing the file or anything else around using dotnet swagger. This seems to be a general issue, not relating to a specific version of the cli.

Repro:

Example:

PS C:\dev\> try{dotnet swagger}catch{Write-Host "error occurred."}
You must install or update .NET to run this application.

App: C:\Users\x\.nuget\packages\swashbuckle.aspnetcore.cli\6.1.4\tools\net5.0\any\dotnet-swagger.dll
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '5.0.0' (x64)
.NET location: C:\Program Files\dotnet\

The following frameworks were found:
  6.0.7 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]

Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=x64&rid=win10-x64
PS C:\dev\>

Repro:

An error is also not thrown when the assembly provided is not found:

PS C:\dev\> try{dotnet swagger tofile --output unknown src\unknown.dll v1}catch{Write-Host "error occured."}
Unhandled exception. System.IO.FileNotFoundException: src\unknown.dll
   at Swashbuckle.AspNetCore.Cli.Program.<>c__DisplayClass0_0.<Main>b__2(IDictionary`2 namedArgs) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 41
   at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 68
   at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\CommandRunner.cs:line 59
   at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args) in C:\projects\ahoy\src\Swashbuckle.AspNetCore.Cli\Program.cs:line 121
esmadau commented 2 years ago

Is this related to dotnet cli in general streaming everything to stdout? https://github.com/dotnet/sdk/issues/7289#issuecomment-1204512664

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

martincostello commented 6 months ago

Yep, this is an issue with .NET rather than us. Our code doesn't get executed in this scenario.