Skip to content

Commit 960bb7d

Browse files
Surayya Huseyn ZadaSurayya Huseyn Zada
authored andcommitted
remove BuildEngine null check before logging
1 parent 65837f6 commit 960bb7d

File tree

3 files changed

+15
-38
lines changed

3 files changed

+15
-38
lines changed

src/Containers/Microsoft.NET.Build.Containers/ImagePublisher.cs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static async Task PublishImageAsync(
1313
SourceImageReference sourceImageReference,
1414
DestinationImageReference destinationImageReference,
1515
Microsoft.Build.Utilities.TaskLoggingHelper Log,
16-
bool isSafeLog,
1716
Telemetry telemetry,
1817
CancellationToken cancellationToken)
1918
{
@@ -27,7 +26,6 @@ await PushToLocalRegistryAsync(
2726
sourceImageReference,
2827
destinationImageReference,
2928
Log,
30-
isSafeLog,
3129
telemetry,
3230
cancellationToken,
3331
destinationImageReference.LocalRegistry!.LoadAsync).ConfigureAwait(false);
@@ -38,7 +36,6 @@ await PushToRemoteRegistryAsync(
3836
sourceImageReference,
3937
destinationImageReference,
4038
Log,
41-
isSafeLog,
4239
cancellationToken,
4340
destinationImageReference.RemoteRegistry!.PushAsync,
4441
Strings.ContainerBuilder_ImageUploadedToRegistry).ConfigureAwait(false);
@@ -55,7 +52,6 @@ public static async Task PublishImageAsync(
5552
SourceImageReference sourceImageReference,
5653
DestinationImageReference destinationImageReference,
5754
Microsoft.Build.Utilities.TaskLoggingHelper Log,
58-
bool isSafeLog,
5955
Telemetry telemetry,
6056
CancellationToken cancellationToken)
6157
{
@@ -69,7 +65,6 @@ await PushToLocalRegistryAsync(
6965
sourceImageReference,
7066
destinationImageReference,
7167
Log,
72-
isSafeLog,
7368
telemetry,
7469
cancellationToken,
7570
destinationImageReference.LocalRegistry!.LoadAsync).ConfigureAwait(false);
@@ -80,7 +75,6 @@ await PushToRemoteRegistryAsync(
8075
sourceImageReference,
8176
destinationImageReference,
8277
Log,
83-
isSafeLog,
8478
cancellationToken,
8579
destinationImageReference.RemoteRegistry!.PushManifestListAsync,
8680
Strings.ImageIndexUploadedToRegistry).ConfigureAwait(false);
@@ -97,7 +91,6 @@ private static async Task PushToLocalRegistryAsync<T>(
9791
SourceImageReference sourceImageReference,
9892
DestinationImageReference destinationImageReference,
9993
Microsoft.Build.Utilities.TaskLoggingHelper Log,
100-
bool isSafeLog,
10194
Telemetry telemetry,
10295
CancellationToken cancellationToken,
10396
Func<T, SourceImageReference, DestinationImageReference, CancellationToken, Task> loadFunc)
@@ -112,34 +105,25 @@ private static async Task PushToLocalRegistryAsync<T>(
112105
try
113106
{
114107
await loadFunc(image, sourceImageReference, destinationImageReference, cancellationToken).ConfigureAwait(false);
115-
if (isSafeLog)
116-
{
117-
Log.LogMessage(MessageImportance.High, Strings.ContainerBuilder_ImageUploadedToLocalDaemon, destinationImageReference, localRegistry);
118-
}
108+
Log.LogMessage(MessageImportance.High, Strings.ContainerBuilder_ImageUploadedToLocalDaemon, destinationImageReference, localRegistry);
119109
}
120-
catch (ContainerHttpException e) when (isSafeLog)
110+
catch (ContainerHttpException e)
121111
{
122112
Log.LogErrorFromException(e, true);
123113
}
124114
catch (AggregateException ex) when (ex.InnerException is DockerLoadException dle)
125115
{
126116
telemetry.LogLocalLoadError();
127-
if (isSafeLog)
128-
{
129-
Log.LogErrorFromException(dle, showStackTrace: false);
130-
}
117+
Log.LogErrorFromException(dle, showStackTrace: false);
131118
}
132-
catch (ArgumentException argEx) when (isSafeLog)
119+
catch (ArgumentException argEx)
133120
{
134121
Log.LogErrorFromException(argEx, showStackTrace: false);
135122
}
136123
catch (DockerLoadException dle)
137124
{
138125
telemetry.LogLocalLoadError();
139-
if (isSafeLog)
140-
{
141-
Log.LogErrorFromException(dle, showStackTrace: false);
142-
}
126+
Log.LogErrorFromException(dle, showStackTrace: false);
143127
}
144128
}
145129

@@ -148,7 +132,6 @@ private static async Task PushToRemoteRegistryAsync<T>(
148132
SourceImageReference sourceImageReference,
149133
DestinationImageReference destinationImageReference,
150134
Microsoft.Build.Utilities.TaskLoggingHelper Log,
151-
bool isSafeLog,
152135
CancellationToken cancellationToken,
153136
Func<T, SourceImageReference, DestinationImageReference, CancellationToken, Task> pushFunc,
154137
string successMessage)
@@ -160,20 +143,17 @@ await pushFunc(
160143
sourceImageReference,
161144
destinationImageReference,
162145
cancellationToken).ConfigureAwait(false);
163-
if (isSafeLog)
164-
{
165-
Log.LogMessage(MessageImportance.High, successMessage, destinationImageReference, destinationImageReference.RemoteRegistry!.RegistryName);
166-
}
146+
Log.LogMessage(MessageImportance.High, successMessage, destinationImageReference, destinationImageReference.RemoteRegistry!.RegistryName);
167147
}
168-
catch (UnableToAccessRepositoryException) when (isSafeLog)
148+
catch (UnableToAccessRepositoryException)
169149
{
170150
Log.LogErrorWithCodeFromResources(nameof(Strings.UnableToAccessRepository), destinationImageReference.Repository, destinationImageReference.RemoteRegistry!.RegistryName);
171151
}
172-
catch (ContainerHttpException e) when (isSafeLog)
152+
catch (ContainerHttpException e)
173153
{
174154
Log.LogErrorFromException(e, true);
175155
}
176-
catch (Exception e) when (isSafeLog)
156+
catch (Exception e)
177157
{
178158
Log.LogErrorWithCodeFromResources(nameof(Strings.RegistryOutputPushFailed), e.Message);
179159
Log.LogMessage(MessageImportance.Low, "Details: {0}", e);

src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateImageIndex.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ internal async Task<bool> ExecuteAsync(CancellationToken cancellationToken)
8383

8484
var telemetry = new Telemetry(sourceImageReference, destinationImageReference, Log);
8585

86-
await ImagePublisher.PublishImageAsync(multiArchImage, sourceImageReference, destinationImageReference, Log, BuildEngine != null, telemetry, cancellationToken)
86+
await ImagePublisher.PublishImageAsync(multiArchImage, sourceImageReference, destinationImageReference, Log, telemetry, cancellationToken)
8787
.ConfigureAwait(false);
8888

8989
return !Log.HasLoggedErrors;

src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,10 @@ internal async Task<bool> ExecuteAsync(CancellationToken cancellationToken)
120120
return !Log.HasLoggedErrors;
121121
}
122122

123-
if (BuildEngine != null)
124-
{
125-
(string message, object[] parameters) = SkipPublishing ?
126-
( Strings.ContainerBuilder_StartBuildingImageForRid, new object[] { Repository, ContainerRuntimeIdentifier, sourceImageReference }) :
127-
( Strings.ContainerBuilder_StartBuildingImage, new object[] { Repository, String.Join(",", ImageTags), sourceImageReference });
128-
Log.LogMessage(MessageImportance.High, message, parameters);
129-
}
123+
(string message, object[] parameters) = SkipPublishing ?
124+
( Strings.ContainerBuilder_StartBuildingImageForRid, new object[] { Repository, ContainerRuntimeIdentifier, sourceImageReference }) :
125+
( Strings.ContainerBuilder_StartBuildingImage, new object[] { Repository, String.Join(",", ImageTags), sourceImageReference });
126+
Log.LogMessage(MessageImportance.High, message, parameters);
130127

131128
Layer newLayer = Layer.FromDirectory(PublishDirectory, WorkingDirectory, imageBuilder.IsWindows, imageBuilder.ManifestMediaType);
132129
imageBuilder.AddLayer(newLayer);
@@ -183,7 +180,7 @@ internal async Task<bool> ExecuteAsync(CancellationToken cancellationToken)
183180

184181
if (!SkipPublishing)
185182
{
186-
await ImagePublisher.PublishImageAsync(builtImage, sourceImageReference, destinationImageReference, Log, BuildEngine != null, telemetry, cancellationToken)
183+
await ImagePublisher.PublishImageAsync(builtImage, sourceImageReference, destinationImageReference, Log, telemetry, cancellationToken)
187184
.ConfigureAwait(false);
188185
}
189186

0 commit comments

Comments
 (0)