Skip to content

Commit

Permalink
upgraded logging for #595 log url when connection is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
SimaTian committed Nov 19, 2024
1 parent 1b4266f commit 7d990f8
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ private static async Task<int> PushToRemoteRegistryAsync(ILogger logger, BuiltIm
cancellationToken)).ConfigureAwait(false);
logger.LogInformation(Strings.ContainerBuilder_ImageUploadedToRegistry, destinationImageReference, destinationImageReference.RemoteRegistry.RegistryName);
}
catch (UnableToDownloadFromRepositoryException e)
{
logger.LogError(Resource.FormatString(nameof(Strings.UnableToDownloadFromRepository)), sourceImageReference);
return 1;
}
catch (UnableToAccessRepositoryException)
{
logger.LogError(Resource.FormatString(nameof(Strings.UnableToAccessRepository), destinationImageReference.Repository, destinationImageReference.RemoteRegistry!.RegistryName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.NET.Build.Containers;

internal sealed class UnableToDownloadFromRepositoryException : Exception
{
public UnableToDownloadFromRepositoryException(string repository, string stackTrace)
: base($"The load of the image from registry {repository} has failed. Stack trace: {stackTrace}")
{
}
}
19 changes: 13 additions & 6 deletions src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,22 @@ public async Task<string> DownloadBlobAsync(string repository, Descriptor descri
return localPath;
}

// No local copy, so download one
using Stream responseStream = await _registryAPI.Blob.GetStreamAsync(repository, descriptor.Digest, cancellationToken).ConfigureAwait(false);

string tempTarballPath = ContentStore.GetTempFile();
using (FileStream fs = File.Create(tempTarballPath))

try
{
await responseStream.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
}
// No local copy, so download one
using Stream responseStream = await _registryAPI.Blob.GetStreamAsync(repository, descriptor.Digest, cancellationToken).ConfigureAwait(false);

using (FileStream fs = File.Create(tempTarballPath))
{
await responseStream.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception e)
{
throw new UnableToDownloadFromRepositoryException(repository, e.ToString());
}
cancellationToken.ThrowIfCancellationRequested();

File.Move(tempTarballPath, localPath, overwrite: true);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@
<value>CONTAINER1015: Unable to access the repository '{0}' at tag '{1}' in the registry '{2}'. Please confirm that this name and tag are present in the registry.</value>
<comment>{StrBegins="CONTAINER1015: "}</comment>
</data>
<data name="UnableToDownloadFromRepository" xml:space="preserve">
<value>CONTAINER1018: Unable to download image from the repository '{0}''. Stack trace: {1}</value>
<comment>{StrBegins="CONTAINER1018:" }</comment>
</data>
<data name="UnableToAccessRepository" xml:space="preserve">
<value>CONTAINER1016: Unable to access the repository '{0}' in the registry '{1}'. Please confirm your credentials are correct and that you have access to this repository and registry.</value>
<comment>{StrBegins="CONTAINER1016:" }</comment>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d990f8

Please sign in to comment.