Skip to content

Commit 5864fe7

Browse files
committed
add error description to mixedGraphFormats error
1 parent 57ffdee commit 5864fe7

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,21 @@ struct SymbolGraphLoader {
126126
let foundGraphNotUsingExtensionSymbolFormat = loadedGraphs.values.map(\.usesExtensionSymbolFormat).contains(false)
127127

128128
guard !foundGraphUsingExtensionSymbolFormat || !foundGraphNotUsingExtensionSymbolFormat else {
129-
throw LoadingError.mixedGraphFormats
129+
let usingExtensionSymbolFormat = loadedGraphs.filter { (_, value) in
130+
guard let usesExtensionSymbolFormat = value.usesExtensionSymbolFormat else {
131+
return false
132+
}
133+
return usesExtensionSymbolFormat
134+
}.map(\.key)
135+
136+
let notUsingExtensionSymbolFormat = loadedGraphs.filter { (_, value) in
137+
guard let usesExtensionSymbolFormat = value.usesExtensionSymbolFormat else {
138+
return false
139+
}
140+
return !usesExtensionSymbolFormat
141+
}.map(\.key)
142+
143+
throw LoadingError.mixedGraphFormats(usingExtensionSymbolFormat, notUsingExtensionSymbolFormat)
130144
}
131145

132146
let usingExtensionSymbolFormat = foundGraphUsingExtensionSymbolFormat
@@ -148,8 +162,22 @@ struct SymbolGraphLoader {
148162
(self.unifiedGraphs, self.graphLocations) = graphLoader.finishLoading()
149163
}
150164

151-
private enum LoadingError: Error {
152-
case mixedGraphFormats
165+
private enum LoadingError: DescribedError {
166+
case mixedGraphFormats([URL], [URL])
167+
168+
var errorDescription: String {
169+
switch self {
170+
case let .mixedGraphFormats(usingExtensionSymbolFormat, notUsingExtensionSymbolFormat):
171+
return """
172+
Mixing symbol graph files with and without extension declarations is not supported.
173+
174+
Symbol graph files with extension declarations:
175+
\(usingExtensionSymbolFormat.map(\.absoluteString).joined(separator: "\n"))
176+
Symbol graph files without extension declarations:
177+
\(notUsingExtensionSymbolFormat.map(\.absoluteString).joined(separator: "\n"))
178+
"""
179+
}
180+
}
153181
}
154182

155183
// Alias to declutter code

Tests/SwiftDocCTests/Infrastructure/SymbolGraph/SymbolGraphLoaderTests.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,19 @@ class SymbolGraphLoaderTests: XCTestCase {
436436
let invalid = allGraphs
437437
loader = try makeSymbolGraphLoader(symbolGraphURLs: invalid.map(\.url))
438438
// found non-empty extension graphs with and without extension block symbols -> should throw
439-
do {
440-
try loader.loadAll()
441-
XCTFail("SymbolGraphLoader should throw when encountering a collection of symbol graph files, where some do and some don't use the extension block format")
442-
} catch {}
439+
XCTAssertThrowsError(try loader.loadAll(),
440+
"SymbolGraphLoader should throw when encountering a collection of symbol graph files, where some do and some don't use the extension block format") { error in
441+
XCTAssertFalse(error.localizedDescription.contains(mainGraph.url.absoluteString))
442+
XCTAssertFalse(error.localizedDescription.contains(emptyExtensionGraph.url.absoluteString))
443+
XCTAssert(error.localizedDescription.contains("""
444+
Symbol graph files with extension declarations:
445+
\(extensionBlockFormatExtensionGraph.url.absoluteString)
446+
"""))
447+
XCTAssert(error.localizedDescription.contains("""
448+
Symbol graph files without extension declarations:
449+
\(noExtensionBlockFormatExtensionGraph.url.absoluteString)
450+
"""))
451+
}
443452
}
444453

445454
// MARK: - Helpers

0 commit comments

Comments
 (0)