Skip to content

Commit 2e64b4b

Browse files
committed
Further reduce the severity to a debug-only assertion.
1 parent eb4053a commit 2e64b4b

File tree

2 files changed

+44
-179
lines changed

2 files changed

+44
-179
lines changed

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

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,37 @@ import SymbolKit
1212

1313
/// A set of functions that add relationship information to a topic graph.
1414
struct SymbolGraphRelationshipsBuilder {
15-
/// A namespace for creation of symbol-graph-builder related problems.
16-
private enum NodeProblem {
17-
/// Returns a problem about a source symbol of a given relationship not being found locally.
18-
static func sourceNotFound(_ relationship: SymbolGraph.Relationship) -> Problem {
19-
return Problem(
20-
diagnostic: Diagnostic(
21-
source: nil, severity: .warning, range: nil,identifier: "org.swift.docc.SymbolNodeNotFound",
22-
summary: "Source symbol \(relationship.source.singleQuoted) not found locally, from \(relationship.kind.rawValue.singleQuoted) relationship to \(relationship.target.singleQuoted)",
23-
explanation: """
24-
The "source" of a symbol graph relationship should always refer to a symbol in the same symbol graph file.
25-
If it doesn't, then the tool that created the symbol graph file should move the relationship to the symbol graph file that defines the "source" symbol \
26-
or remove the relationship if none of the created symbol graph file defines the "source" symbol.
27-
28-
The "target" may refer to a symbol in another module.
29-
For example, if local symbol conforms to a protocol from another module, \
30-
there will be a "{ source: local-symbol-ID, kind: conformsTo, target: protocol-in-other-module-ID }" relationship.
31-
32-
A symbol graph relationship with a non-local "source" symbol is a bug in the tool that created the symbol graph file.
33-
"""
34-
),
35-
possibleSolutions: []
36-
)
15+
/// A namespace for debug assert messages for data-correctness issues in the symbol graph data.
16+
private enum AssertionMessages {
17+
static func sourceNotFound(_ relationship: SymbolGraph.Relationship) -> String {
18+
"""
19+
Source symbol \(relationship.source.singleQuoted) not found locally, from \(relationship.kind.rawValue.singleQuoted) relationship to \(relationship.target.singleQuoted).
20+
21+
The "source" of a symbol graph relationship should always refer to a symbol in the same symbol graph file.
22+
If it doesn't, then the tool that created the symbol graph file should move the relationship to the symbol graph file that defines the "source" symbol \
23+
or remove the relationship if none of the created symbol graph file defines the "source" symbol.
24+
25+
The "target" may refer to a symbol in another module.
26+
For example, if local symbol conforms to a protocol from another module, \
27+
there will be a "{ source: local-symbol-ID, kind: conformsTo, target: protocol-in-other-module-ID }" relationship.
28+
29+
A symbol graph relationship with a non-local "source" symbol is a bug in the tool that created the symbol graph file.
30+
"""
3731
}
38-
/// Returns a problem about a target symbol of an overload group not being found locally.
39-
static func overloadGroupNotFound(_ relationship: SymbolGraph.Relationship) -> Problem {
40-
return Problem(
41-
diagnostic: Diagnostic(
42-
source: nil, severity: .error, range: nil,identifier: "org.swift.docc.SymbolNodeNotFound",
43-
summary: "Overload group \(relationship.source.singleQuoted) not found locally, from \(relationship.kind.rawValue.singleQuoted) relationship of \(relationship.source.singleQuoted)",
44-
explanation: """
45-
Both the "source" and "target" of an \(relationship.kind.rawValue.singleQuoted) symbol graph relationships with should always refer to symbols in the same symbol graph file.
46-
A \(relationship.kind.rawValue.singleQuoted) symbol graph relationship with a non-local "target" symbol is a bug in the tool that created the symbol graph file.
47-
"""
48-
),
49-
possibleSolutions: []
50-
)
32+
33+
static func overloadGroupNotFound(_ relationship: SymbolGraph.Relationship) -> String {
34+
"""
35+
Overload group \(relationship.source.singleQuoted) not found locally, from \(relationship.kind.rawValue.singleQuoted) relationship of \(relationship.source.singleQuoted).
36+
37+
Both the "source" and "target" of an \(relationship.kind.rawValue.singleQuoted) symbol graph relationships with should always refer to symbols in the same symbol graph file.
38+
A \(relationship.kind.rawValue.singleQuoted) symbol graph relationship with a non-local "target" symbol is a bug in the tool that created the symbol graph file.
39+
"""
5140
}
52-
/// Returns a problem about a node with the given reference not being found.
53-
static func invalidReference(_ reference: String) -> Problem {
54-
return Problem(diagnostic: Diagnostic(source: nil, severity: .error, range: nil, identifier: "org.swift.docc.InvalidSymbolIdentifier", summary: "Relationship symbol path \(reference.singleQuoted) isn't valid"), possibleSolutions: [])
41+
42+
static func invalidSymbolReference(_ reference: SymbolReference) -> String {
43+
return """
44+
Failed to create an unresolved reference for \(reference.path.singleQuoted). It contains characters that are not allowed in the "path" of a RFC 3986 URL.
45+
"""
5546
}
5647
}
5748

@@ -78,7 +69,7 @@ struct SymbolGraphRelationshipsBuilder {
7869
let implementorSymbol = implementorNode.semantic as? Symbol
7970
else {
8071
// The source node for implementation relationship not found.
81-
engine.emit(NodeProblem.sourceNotFound(edge))
72+
assertionFailure(AssertionMessages.sourceNotFound(edge))
8273
return
8374
}
8475

@@ -94,7 +85,7 @@ struct SymbolGraphRelationshipsBuilder {
9485
let symbolReference = SymbolReference(edge.target, interfaceLanguage: language, symbol: localCache[edge.target]?.symbol)
9586
guard let unresolved = UnresolvedTopicReference(symbolReference: symbolReference, bundle: bundle) else {
9687
// The symbol reference format is invalid.
97-
engine.emit(NodeProblem.invalidReference(symbolReference.path))
88+
assertionFailure(AssertionMessages.invalidSymbolReference(symbolReference))
9889
return
9990
}
10091

@@ -128,7 +119,7 @@ struct SymbolGraphRelationshipsBuilder {
128119
// Make the implementation a child of the requirement
129120
guard let childReference = localCache.reference(symbolID: edge.source) else {
130121
// The child wasn't found, invalid reference in relationship.
131-
engine.emit(SymbolGraphRelationshipsBuilder.NodeProblem.sourceNotFound(edge))
122+
assertionFailure(SymbolGraphRelationshipsBuilder.AssertionMessages.sourceNotFound(edge))
132123
return
133124
}
134125

@@ -163,7 +154,7 @@ struct SymbolGraphRelationshipsBuilder {
163154
let conformingSymbol = conformingNode.semantic as? Symbol
164155
else {
165156
// The source node for conformance relationship not found.
166-
engine.emit(NodeProblem.sourceNotFound(edge))
157+
assertionFailure(AssertionMessages.sourceNotFound(edge))
167158
return
168159
}
169160

@@ -184,7 +175,7 @@ struct SymbolGraphRelationshipsBuilder {
184175
let symbolReference = SymbolReference(edge.target, interfaceLanguage: language, symbol: localCache[edge.target]?.symbol)
185176
guard let unresolved = UnresolvedTopicReference(symbolReference: symbolReference, bundle: bundle) else {
186177
// The symbol reference format is invalid.
187-
engine.emit(NodeProblem.invalidReference(symbolReference.path))
178+
assertionFailure(AssertionMessages.invalidSymbolReference(symbolReference))
188179
return
189180
}
190181
conformanceNodeReference = .unresolved(unresolved)
@@ -252,7 +243,7 @@ struct SymbolGraphRelationshipsBuilder {
252243
let childSymbol = childNode.semantic as? Symbol
253244
else {
254245
// The source node for inheritance relationship not found.
255-
engine.emit(NodeProblem.sourceNotFound(edge))
246+
assertionFailure(AssertionMessages.sourceNotFound(edge))
256247
return
257248
}
258249

@@ -271,7 +262,7 @@ struct SymbolGraphRelationshipsBuilder {
271262
let symbolReference = SymbolReference(edge.target, interfaceLanguage: language, symbol: nil)
272263
guard let unresolved = UnresolvedTopicReference(symbolReference: symbolReference, bundle: bundle) else {
273264
// The symbol reference format is invalid.
274-
engine.emit(NodeProblem.invalidReference(symbolReference.path))
265+
assertionFailure(AssertionMessages.invalidSymbolReference(symbolReference))
275266
return
276267
}
277268
parentNodeReference = .unresolved(unresolved)
@@ -352,7 +343,7 @@ struct SymbolGraphRelationshipsBuilder {
352343
let requiredSymbol = requiredNode.semantic as? Symbol
353344
else {
354345
// The source node for requirement relationship not found.
355-
engine.emit(NodeProblem.sourceNotFound(edge))
346+
assertionFailure(AssertionMessages.sourceNotFound(edge))
356347
return
357348
}
358349
requiredSymbol.isRequired = required
@@ -469,11 +460,11 @@ struct SymbolGraphRelationshipsBuilder {
469460
engine: DiagnosticEngine
470461
) {
471462
guard let overloadNode = localCache[edge.source] else {
472-
engine.emit(NodeProblem.sourceNotFound(edge))
463+
assertionFailure(AssertionMessages.sourceNotFound(edge))
473464
return
474465
}
475466
guard let overloadGroupNode = localCache[edge.target] else {
476-
engine.emit(NodeProblem.overloadGroupNotFound(edge))
467+
assertionFailure(AssertionMessages.overloadGroupNotFound(edge))
477468
return
478469
}
479470

0 commit comments

Comments
 (0)