dotnet / sdk-container-builds

Libraries and build tooling to create container images from .NET projects using MSBuild
https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
MIT License
179 stars 34 forks source link

Have a user-friendlier error message when the base container image is not found #465

Closed tmds closed 11 months ago

tmds commented 1 year ago

When the user specifies a container base image tag that does not exists, currently this surfaces as a 404 Not Found exception:

 MSB4018: The "CreateNewImage" task failed unexpectedly. [/tmp/web/web.csproj]
 MSB4018: System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found). [/tmp/web/web.csproj]
 MSB4018:    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() [/tmp/web/web.csproj]
 MSB4018:    at Microsoft.NET.Build.Containers.Registry.GetManifestAsync(String repositoryName, String reference, CancellationToken cancellationToken) in /_/src/sdk/artifacts/source-build/self/src/src/Containers/Microsoft.NET.Build.Containers/Registry.cs:line 230 [/tmp/web/web.csproj]
 MSB4018:    at Microsoft.NET.Build.Containers.Registry.GetImageManifestAsync(String repositoryName, String reference, String runtimeIdentifier, String runtimeIdentifierGraphPath, CancellationToken cancellationToken) in /_/src/sdk/artifacts/source-build/self/src/src/Containers/Microsoft.NET.Build.Containers/Registry.cs:line 157 [/tmp/web/web.csproj]
 MSB4018:    at Microsoft.NET.Build.Containers.Tasks.CreateNewImage.ExecuteAsync(CancellationToken cancellationToken) in /_/src/sdk/artifacts/source-build/self/src/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs:line 49 [/tmp/web/web.csproj]
 MSB4018:    at Microsoft.NET.Build.Containers.Tasks.CreateNewImage.Execute() in /_/src/sdk/artifacts/source-build/self/src/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs:line 32 [/tmp/web/web.csproj]
 MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/tmp/web/web.csproj]
 MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/tmp/web/web.csproj]

cc @baronfel

baronfel commented 1 year ago

Definitely agree - we'd gladly take any enhancements here! In general we should remove all uses of EnsureSuccessStatusCode() in the codebase and replace them with more bespoke errors/messages.

baronfel commented 1 year ago

Implemented in https://github.com/dotnet/sdk/pull/34460

baronfel commented 11 months ago

Closing - we did this in RC2!