From b16f488dfbf67257a95e688fdd57345cb642f953 Mon Sep 17 00:00:00 2001 From: Raul Portugues del Peno Date: Wed, 29 Jan 2025 09:56:17 +0100 Subject: [PATCH] Add error logging --- .../swiftpm/SwiftResolvedComponentDetector.cs | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs index a9f782ed..6d6edc0c 100644 --- a/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/swiftpm/SwiftResolvedComponentDetector.cs @@ -63,27 +63,34 @@ private void ProcessPackageResolvedFile(ISingleFileComponentRecorder singleFileC foreach (var package in parsedResolvedFile.Pins) { - if (package.Kind == TargetSwiftPackageKind) + try { - // The version of the package is not always available. - var version = package.State.Version ?? package.State.Branch ?? package.State.Revision; - - var detectedSwiftComponent = new SwiftComponent( - name: package.Identity, - version: version, - packageUrl: package.Location, - hash: package.State.Revision); - var newDetectedSwiftComponent = new DetectedComponent(component: detectedSwiftComponent, detector: this); - singleFileComponentRecorder.RegisterUsage(newDetectedSwiftComponent); - - // We also register a Git component for the same package so that the git URL is registered. - // Swift Package Manager directly downloads the package from the git URL. - var detectedGitComponent = new GitComponent( - repositoryUrl: new Uri(package.Location), - commitHash: package.State.Revision, - tag: version); - var newDetectedGitComponent = new DetectedComponent(component: detectedGitComponent, detector: this); - singleFileComponentRecorder.RegisterUsage(newDetectedGitComponent); + if (package.Kind == TargetSwiftPackageKind) + { + // The version of the package is not always available. + var version = package.State.Version ?? package.State.Branch ?? package.State.Revision; + + var detectedSwiftComponent = new SwiftComponent( + name: package.Identity, + version: version, + packageUrl: package.Location, + hash: package.State.Revision); + var newDetectedSwiftComponent = new DetectedComponent(component: detectedSwiftComponent, detector: this); + singleFileComponentRecorder.RegisterUsage(newDetectedSwiftComponent); + + // We also register a Git component for the same package so that the git URL is registered. + // Swift Package Manager directly downloads the package from the git URL. + var detectedGitComponent = new GitComponent( + repositoryUrl: new Uri(package.Location), + commitHash: package.State.Revision, + tag: version); + var newDetectedGitComponent = new DetectedComponent(component: detectedGitComponent, detector: this); + singleFileComponentRecorder.RegisterUsage(newDetectedGitComponent); + } + } + catch (Exception exception) + { + this.Logger.LogError(exception, "SwiftComponentDetector: Error processing package: {Package}", package.Identity); } } }