dotnet / Docker.DotNet

:whale: .NET (C#) Client Library for Docker API
https://www.nuget.org/packages/Docker.DotNet/
MIT License
2.26k stars 382 forks source link

Handling errors when building image #555

Open dermeister opened 2 years ago

dermeister commented 2 years ago

Output of dotnet --info:

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  3.1.410 [/usr/local/share/dotnet/sdk]
  5.0.103 [/usr/local/share/dotnet/sdk]
  5.0.302 [/usr/local/share/dotnet/sdk]
  6.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

What version of Docker.DotNet?:

3.125.5

Steps to reproduce the issue:

  1. Try building image with invalid syntax in Dockerfile using BuildImageFromDockerfileAsync method.

What actually happened?: BuildImageFromDockerfileAsync doesn't throw any exception. Instead, it ignores status code and reports everything to IProgress instance. When Dockerfile contains syntax errors, docker daemon responds with status code 400 and body which cannot be deserialized to JSONMessage (it contains only "message" field), so it's impossible to handle exceptions from building image.

What did you expect to happen?: BuildImageFromDockerfileAsync should throw exception if daemon responds with error.

daniel-tonic commented 2 years ago

And/Or, the JSONMessage needs to be updated to have a "message" field so that we can get the error from progress. Either way, can confirm that errors from Build and Create (and likely others) are basically being eaten. The only indication that anything went wrong was that nothing was return but a single hit to IProgress with an empty JSONMessage.

dermeister commented 2 years ago

I don't think that updating JSONMessage is a good idea, because it's generated from Docker sources and should be in sync with it. Plus, it would be inconsistent way of exception handling if we consider other API methods.

HofmeisterAn commented 2 years ago

@galvesribeiro We can close this issue.

aDisplayName commented 2 years ago

@galvesribeiro , I'm still new on GitHub process here, so do you know who will trigger a new release build so that the fix can be available to the official nuget packages? 😀

HofmeisterAn commented 2 years ago

Usually it depends how urgent the issue is. If it is not critical (like in this case) we probably collect some more fixes and publish them together. @galvesribeiro will do the release at some point.