Skip to content

Commit fbfec90

Browse files
jpinzCopilot
andcommitted
Address PR comments.
Co-authored-by: Copilot <copilot@github.com>
1 parent 330d5fc commit fbfec90

4 files changed

Lines changed: 10 additions & 16 deletions

File tree

src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,18 @@ public static bool HasUnresolvedVariables(string reference) =>
4949

5050
/// <summary>
5151
/// Attempts to parse an image reference string into a <see cref="DockerReference"/>.
52-
/// Returns <c>null</c> if the reference contains unresolved variables or cannot be parsed.
52+
/// Returns <c>null</c> if the reference contains unresolved variables.
5353
/// </summary>
5454
/// <param name="imageReference">The image reference string to parse.</param>
55-
/// <returns>A <see cref="DockerReference"/> if parsing succeeds; otherwise <c>null</c>.</returns>
55+
/// <returns>A <see cref="DockerReference"/> if parsing succeeds; otherwise <c>null</c> if it has unresolved variables, or an exception is thrown.</returns>
5656
public static DockerReference? TryParseImageReference(string imageReference)
5757
{
5858
if (HasUnresolvedVariables(imageReference))
5959
{
6060
return null;
6161
}
6262

63-
try
64-
{
65-
return ParseFamiliarName(imageReference);
66-
}
67-
catch
68-
{
69-
return null;
70-
}
63+
return ParseFamiliarName(imageReference);
7164
}
7265

7366
/// <summary>

src/Microsoft.ComponentDetection.Detectors/dockercompose/DockerComposeComponentDetector.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable enable
21
namespace Microsoft.ComponentDetection.Detectors.DockerCompose;
32

43
using System;

src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable enable
21
namespace Microsoft.ComponentDetection.Detectors.Dockerfile;
32

43
using System;

test/Microsoft.ComponentDetection.Common.Tests/DockerReferenceUtilityTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ public void TryParseImageReference_ReturnsNullForUnresolvedVariables()
296296
}
297297

298298
[TestMethod]
299-
public void TryParseImageReference_ReturnsNullForInvalidReference()
299+
public void TryParseImageReference_ThrowsForInvalidReference()
300300
{
301-
DockerReferenceUtility.TryParseImageReference("docker.io/library/Nginx").Should().BeNull();
301+
var func = () => DockerReferenceUtility.TryParseImageReference("docker.io/library/Nginx");
302+
303+
func.Should().Throw<ReferenceNameContainsUppercaseException>();
302304
}
303305

304306
[TestMethod]
@@ -355,12 +357,13 @@ public void TryRegisterImageReference_SkipsUnresolvedVariables()
355357
}
356358

357359
[TestMethod]
358-
public void TryRegisterImageReference_SkipsInvalidReference()
360+
public void TryRegisterImageReference_ThrowsForInvalidReference()
359361
{
360362
var recorder = new Mock<ISingleFileComponentRecorder>();
361363

362-
DockerReferenceUtility.TryRegisterImageReference("docker.io/library/Nginx", recorder.Object);
364+
var func = () => DockerReferenceUtility.TryRegisterImageReference("docker.io/library/Nginx", recorder.Object);
363365

366+
func.Should().Throw<ReferenceNameContainsUppercaseException>();
364367
recorder.Verify(r => r.RegisterUsage(It.IsAny<DetectedComponent>(), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<bool?>(), It.IsAny<DependencyScope?>(), It.IsAny<string>()), Times.Never);
365368
}
366369
}

0 commit comments

Comments
 (0)