@@ -25,13 +25,12 @@ extension CheckedIndex {
25
25
/// the same result every time.
26
26
package func primaryDefinitionOrDeclarationOccurrence(
27
27
ofDocCSymbolLink symbolLink: DocCSymbolLink ,
28
- fetchSymbolGraph: @Sendable ( _ : SymbolLocation) async throws -> String ?
28
+ fetchSymbolGraph: @Sendable ( SymbolLocation) async throws -> String ?
29
29
) async throws -> SymbolOccurrence ? {
30
- guard ! symbolLink. components. isEmpty else {
31
- return nil
30
+ guard let topLevelSymbolName = symbolLink. components. last ? . name else {
31
+ throw DocCCheckedIndexError . emptyDocCSymbolLink
32
32
}
33
33
// Find all occurrences of the symbol by name alone
34
- let topLevelSymbolName = symbolLink. components. last!. name
35
34
var topLevelSymbolOccurrences : [ SymbolOccurrence ] = [ ]
36
35
forEachCanonicalSymbolOccurrence ( byName: topLevelSymbolName) { symbolOccurrence in
37
36
topLevelSymbolOccurrences. append ( symbolOccurrence)
@@ -60,7 +59,7 @@ extension CheckedIndex {
60
59
/// - fetchSymbolGraph: Callback that returns a SymbolGraph for a given SymbolLocation
61
60
package func doccSymbolInformation(
62
61
ofUSR usr: String ,
63
- fetchSymbolGraph: ( _ : SymbolLocation ) async throws -> String ?
62
+ fetchSymbolGraph: ( SymbolLocation ) async throws -> String ?
64
63
) async throws -> DocCSymbolInformation ? {
65
64
guard let topLevelSymbolOccurrence = primaryDefinitionOrDeclarationOccurrence ( ofUSR: usr) else {
66
65
return nil
@@ -77,18 +76,35 @@ extension CheckedIndex {
77
76
var components = [ DocCSymbolInformation . Component ( fromModuleName: moduleName) ]
78
77
for symbolOccurence in symbols {
79
78
guard let rawSymbolGraph = try await fetchSymbolGraph ( symbolOccurence. location) else {
80
- return nil
79
+ throw DocCCheckedIndexError . noSymbolGraph ( symbolOccurence . symbol . usr )
81
80
}
82
81
let symbolGraph = try JSONDecoder ( ) . decode ( SymbolGraph . self, from: Data ( rawSymbolGraph. utf8) )
83
82
guard let symbol = symbolGraph. symbols [ symbolOccurence. symbol. usr] else {
84
- return nil
83
+ throw DocCCheckedIndexError . symbolNotFound ( symbolOccurence . symbol . usr )
85
84
}
86
85
components. append ( DocCSymbolInformation . Component ( fromSymbol: symbol) )
87
86
}
88
87
return DocCSymbolInformation ( components: components)
89
88
}
90
89
}
91
90
91
+ enum DocCCheckedIndexError : LocalizedError {
92
+ case emptyDocCSymbolLink
93
+ case noSymbolGraph( String )
94
+ case symbolNotFound( String )
95
+
96
+ var errorDescription : String ? {
97
+ switch self {
98
+ case . emptyDocCSymbolLink:
99
+ " The provided DocCSymbolLink was empty and could not be resolved "
100
+ case . noSymbolGraph( let usr) :
101
+ " Unable to locate symbol graph for \( usr) "
102
+ case . symbolNotFound( let usr) :
103
+ " Symbol \( usr) was not found in its symbol graph "
104
+ }
105
+ }
106
+ }
107
+
92
108
extension SymbolOccurrence {
93
109
func parent( _ index: CheckedIndex ) -> SymbolOccurrence ? {
94
110
let allParentRelations =
0 commit comments