Skip to content

Commit c1895c3

Browse files
add logging to BuildSystemIntegrationExtensions
1 parent 0e05bca commit c1895c3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Sources/DocCDocumentation/BuildSystemIntegrationExtensions.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ package import BuildServerProtocol
1414
package import BuildSystemIntegration
1515
package import Foundation
1616
import LanguageServerProtocol
17+
import SKLogging
1718

1819
package extension BuildSystemManager {
1920
/// Retrieves the name of the Swift module for a given target.
2021
///
2122
/// - Parameter target: The build target identifier
2223
/// - Returns: The name of the Swift module or nil if it could not be determined
2324
func moduleName(for target: BuildTargetIdentifier) async -> String? {
24-
let sourceFiles = (try? await sourceFiles(in: [target]).flatMap(\.sources)) ?? []
25+
let sourceFiles =
26+
await orLog(
27+
"Failed to retreive source files from target \(target.uri)",
28+
{ try await self.sourceFiles(in: [target]).flatMap(\.sources) }
29+
) ?? []
2530
for sourceFile in sourceFiles {
2631
let language = await defaultLanguage(for: sourceFile.uri, in: target)
2732
guard language == .swift else {
@@ -39,7 +44,11 @@ package extension BuildSystemManager {
3944
/// - Parameter target: The build target identifier
4045
/// - Returns: The URL of the documentation catalog or nil if one could not be found
4146
func doccCatalog(for target: BuildTargetIdentifier) async -> URL? {
42-
let sourceFiles = (try? await sourceFiles(in: [target]).flatMap(\.sources)) ?? []
47+
let sourceFiles =
48+
await orLog(
49+
"Failed to retreive source files from target \(target.uri)",
50+
{ try await self.sourceFiles(in: [target]).flatMap(\.sources) }
51+
) ?? []
4352
let catalogURLs = sourceFiles.compactMap { sourceItem -> URL? in
4453
guard sourceItem.dataKind == .sourceKit,
4554
let data = SourceKitSourceItemData(fromLSPAny: sourceItem.data),
@@ -49,6 +58,9 @@ package extension BuildSystemManager {
4958
}
5059
return sourceItem.uri.fileURL
5160
}.sorted(by: { $0.absoluteString >= $1.absoluteString })
61+
if catalogURLs.count > 1 {
62+
logger.error("Multiple SwiftDocC catalogs found in build target \(target.uri)")
63+
}
5264
return catalogURLs.first
5365
}
5466
}

0 commit comments

Comments
 (0)