Skip to content

Commit b16f488

Browse files
committed
Add error logging
1 parent 7a9e269 commit b16f488

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,34 @@ private void ProcessPackageResolvedFile(ISingleFileComponentRecorder singleFileC
6363

6464
foreach (var package in parsedResolvedFile.Pins)
6565
{
66-
if (package.Kind == TargetSwiftPackageKind)
66+
try
6767
{
68-
// The version of the package is not always available.
69-
var version = package.State.Version ?? package.State.Branch ?? package.State.Revision;
70-
71-
var detectedSwiftComponent = new SwiftComponent(
72-
name: package.Identity,
73-
version: version,
74-
packageUrl: package.Location,
75-
hash: package.State.Revision);
76-
var newDetectedSwiftComponent = new DetectedComponent(component: detectedSwiftComponent, detector: this);
77-
singleFileComponentRecorder.RegisterUsage(newDetectedSwiftComponent);
78-
79-
// We also register a Git component for the same package so that the git URL is registered.
80-
// Swift Package Manager directly downloads the package from the git URL.
81-
var detectedGitComponent = new GitComponent(
82-
repositoryUrl: new Uri(package.Location),
83-
commitHash: package.State.Revision,
84-
tag: version);
85-
var newDetectedGitComponent = new DetectedComponent(component: detectedGitComponent, detector: this);
86-
singleFileComponentRecorder.RegisterUsage(newDetectedGitComponent);
68+
if (package.Kind == TargetSwiftPackageKind)
69+
{
70+
// The version of the package is not always available.
71+
var version = package.State.Version ?? package.State.Branch ?? package.State.Revision;
72+
73+
var detectedSwiftComponent = new SwiftComponent(
74+
name: package.Identity,
75+
version: version,
76+
packageUrl: package.Location,
77+
hash: package.State.Revision);
78+
var newDetectedSwiftComponent = new DetectedComponent(component: detectedSwiftComponent, detector: this);
79+
singleFileComponentRecorder.RegisterUsage(newDetectedSwiftComponent);
80+
81+
// We also register a Git component for the same package so that the git URL is registered.
82+
// Swift Package Manager directly downloads the package from the git URL.
83+
var detectedGitComponent = new GitComponent(
84+
repositoryUrl: new Uri(package.Location),
85+
commitHash: package.State.Revision,
86+
tag: version);
87+
var newDetectedGitComponent = new DetectedComponent(component: detectedGitComponent, detector: this);
88+
singleFileComponentRecorder.RegisterUsage(newDetectedGitComponent);
89+
}
90+
}
91+
catch (Exception exception)
92+
{
93+
this.Logger.LogError(exception, "SwiftComponentDetector: Error processing package: {Package}", package.Identity);
8794
}
8895
}
8996
}

0 commit comments

Comments
 (0)