aspnet / LibraryManager

Other
447 stars 78 forks source link

LibMan CLI returns zero exit code even when there was an error #682

Closed msvprogs closed 2 months ago

msvprogs commented 2 years ago

Describe the bug

Even if LibMan CLI operation has finished with errors, exit code of the process is 0. This is a little inconvenient for build scripts or Dockerfiles when you don't know that some libraries haven't been restored, for example, because of library CDN provider's temporary unavailability or bugs. The only workaround is to check stderr and fail when there is any output, but it seems that returning non-zero exit code would be a more clear indication that something went wrong.

To Reproduce

Steps to reproduce the behavior:

  1. Create temporary Docker container with .NET 5.0 SDK and attach to its terminal:
    sudo docker run --rm -it mcr.microsoft.com/dotnet/sdk:5.0
  2. Install LibMan CLI tool
    export PATH="$PATH:/root/.dotnet/tools"
    dotnet tool install -g Microsoft.Web.LibraryManager.Cli
  3. Perform any illegal operation. For example, try to restore libraries in the directory without libman.json file.
    root@0f7d49cfdfcc:/# libman restore
    libman.json was not found:/libman.json
  4. Check exit code of libman:
    root@0f7d49cfdfcc:/# echo $?
    0
  5. Exit code is zero despite libman command failure

Expected behavior

Exit code of libman is non-zero

Additional context

LibMan CLI version: 2.1.161+abc97ecc7d.RR