Skip to content

Commit 0955d2e

Browse files
Detect and report docker load errors (#107)
We may want to have a more sophisticated way of dealing with this in the future but this gives users a fighting chance of understand what went wrong + better error reports for us.
1 parent f93bb96 commit 0955d2e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Microsoft.NET.Build.Containers/CreateNewImage.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,15 @@ public override bool Execute()
113113

114114
if (OutputRegistry.StartsWith("docker://"))
115115
{
116-
LocalDocker.Load(image, ImageName, ImageTag, BaseImageName).Wait();
116+
try
117+
{
118+
LocalDocker.Load(image, ImageName, ImageTag, BaseImageName).Wait();
119+
}
120+
catch (AggregateException ex) when (ex.InnerException is DockerLoadException dle)
121+
{
122+
Log.LogErrorFromException(dle, showStackTrace: false);
123+
return !Log.HasLoggedErrors;
124+
}
117125
}
118126
else
119127
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Microsoft.NET.Build.Containers
4+
{
5+
public class DockerLoadException : Exception
6+
{
7+
public DockerLoadException()
8+
{
9+
}
10+
11+
public DockerLoadException(string? message) : base(message)
12+
{
13+
}
14+
15+
public DockerLoadException(string? message, Exception? innerException) : base(message, innerException)
16+
{
17+
}
18+
19+
protected DockerLoadException(SerializationInfo info, StreamingContext context) : base(info, context)
20+
{
21+
}
22+
}
23+
}

Microsoft.NET.Build.Containers/LocalDocker.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static async Task Load(Image x, string name, string tag, string baseName)
1414
ProcessStartInfo loadInfo = new("docker", $"load");
1515
loadInfo.RedirectStandardInput = true;
1616
loadInfo.RedirectStandardOutput = true;
17+
loadInfo.RedirectStandardError = true;
1718

1819
using Process? loadProcess = Process.Start(loadInfo);
1920

@@ -29,6 +30,11 @@ public static async Task Load(Image x, string name, string tag, string baseName)
2930
loadProcess.StandardInput.Close();
3031

3132
await loadProcess.WaitForExitAsync();
33+
34+
if (loadProcess.ExitCode != 0)
35+
{
36+
throw new DockerLoadException($"Failed to load image to local Docker daemon. stdout: {await loadProcess.StandardError.ReadToEndAsync()}");
37+
}
3238
}
3339

3440
public static async Task WriteImageToStream(Image x, string name, string tag, Stream imageStream)

0 commit comments

Comments
 (0)