@@ -19,7 +19,11 @@ struct DiagnosticReportBuilder {
19
19
private var lineNumbers : [ Incompatibility : Int ] = [ : ]
20
20
private let provider : ContainerProvider
21
21
22
- init ( root: DependencyResolutionNode , incompatibilities: [ DependencyResolutionNode : [ Incompatibility ] ] , provider: ContainerProvider ) {
22
+ init (
23
+ root: DependencyResolutionNode ,
24
+ incompatibilities: [ DependencyResolutionNode : [ Incompatibility ] ] ,
25
+ provider: ContainerProvider
26
+ ) {
23
27
self . rootNode = root
24
28
self . incompatibilities = incompatibilities
25
29
self . provider = provider
@@ -41,20 +45,20 @@ struct DiagnosticReportBuilder {
41
45
try self . visit ( rootCause)
42
46
} else {
43
47
assertionFailure ( " Unimplemented " )
44
- self . record (
48
+ try self . record (
45
49
rootCause,
46
- message: try self . description ( for: rootCause) ,
50
+ message: self . description ( for: rootCause) ,
47
51
isNumbered: false
48
52
)
49
53
}
50
54
51
- var content : String = " "
55
+ var content = " "
52
56
let padding = self . lineNumbers. isEmpty ? 0 : " \( Array ( self . lineNumbers. values) . last!) " . count
53
57
54
58
for (idx, line) in self . lines. enumerated ( ) {
55
59
content += String ( repeating: " " , count: padding)
56
60
if line. number != - 1 {
57
- content += String ( repeating: " " , count: padding)
61
+ content += String ( repeating: " " , count: padding)
58
62
content += " ( \( line. number) ) "
59
63
}
60
64
content += line. message. prefix ( 1 ) . capitalized
@@ -86,9 +90,9 @@ struct DiagnosticReportBuilder {
86
90
let otherLine = self . lineNumbers [ cause. other]
87
91
88
92
if let conflictLine, let otherLine {
89
- self . record (
93
+ try self . record (
90
94
incompatibility,
91
- message: " \( incompatibilityDesc) because \( try self . description ( for: cause. conflict) ) ( \( conflictLine) ) and \( try self . description ( for: cause. other) ) ( \( otherLine) . " ,
95
+ message: " \( incompatibilityDesc) because \( self . description ( for: cause. conflict) ) ( \( conflictLine) ) and \( self . description ( for: cause. other) ) ( \( otherLine) . " ,
92
96
isNumbered: isNumbered
93
97
)
94
98
} else if conflictLine != nil || otherLine != nil {
@@ -106,9 +110,9 @@ struct DiagnosticReportBuilder {
106
110
}
107
111
108
112
try self . visit ( withoutLine)
109
- self . record (
113
+ try self . record (
110
114
incompatibility,
111
- message: " \( conjunction) \( incompatibilityDesc) because \( try self . description ( for: withLine) ) \( line) . " ,
115
+ message: " \( conjunction) \( incompatibilityDesc) because \( self . description ( for: withLine) ) \( line) . " ,
112
116
isNumbered: isNumbered
113
117
)
114
118
} else {
@@ -127,9 +131,9 @@ struct DiagnosticReportBuilder {
127
131
} else {
128
132
try self . visit ( cause. conflict, isConclusion: true )
129
133
try self . visit ( cause. other)
130
- self . record (
134
+ try self . record (
131
135
incompatibility,
132
- message: " \( conjunction) \( incompatibilityDesc) because \( try self . description ( for: cause. conflict) ) ( \( self . lineNumbers [ cause. conflict] !) ). " ,
136
+ message: " \( conjunction) \( incompatibilityDesc) because \( self . description ( for: cause. conflict) ) ( \( self . lineNumbers [ cause. conflict] !) ). " ,
133
137
isNumbered: isNumbered
134
138
)
135
139
}
@@ -139,9 +143,9 @@ struct DiagnosticReportBuilder {
139
143
let ext = cause. conflict. cause. isConflict ? cause. other : cause. conflict
140
144
let derivedLine = self . lineNumbers [ derived]
141
145
if let derivedLine {
142
- self . record (
146
+ try self . record (
143
147
incompatibility,
144
- message: " \( incompatibilityDesc) because \( try self . description ( for: ext) ) and \( try self . description ( for: derived) ) ( \( derivedLine) ). " ,
148
+ message: " \( incompatibilityDesc) because \( self . description ( for: ext) ) and \( self . description ( for: derived) ) ( \( derivedLine) ). " ,
145
149
isNumbered: isNumbered
146
150
)
147
151
} else if self . isCollapsible ( derived) {
@@ -150,27 +154,28 @@ struct DiagnosticReportBuilder {
150
154
return
151
155
}
152
156
153
- let collapsedDerived = derivedCause. conflict. cause. isConflict ? derivedCause. conflict : derivedCause. other
157
+ let collapsedDerived = derivedCause. conflict. cause. isConflict ? derivedCause. conflict : derivedCause
158
+ . other
154
159
let collapsedExt = derivedCause. conflict. cause. isConflict ? derivedCause. other : derivedCause. conflict
155
160
156
161
try self . visit ( collapsedDerived)
157
- self . record (
162
+ try self . record (
158
163
incompatibility,
159
- message: " \( conjunction) \( incompatibilityDesc) because \( try self . description ( for: collapsedExt) ) and \( try self . description ( for: ext) ) . " ,
164
+ message: " \( conjunction) \( incompatibilityDesc) because \( self . description ( for: collapsedExt) ) and \( self . description ( for: ext) ) . " ,
160
165
isNumbered: isNumbered
161
166
)
162
167
} else {
163
168
try self . visit ( derived)
164
- self . record (
169
+ try self . record (
165
170
incompatibility,
166
- message: " \( conjunction) \( incompatibilityDesc) because \( try self . description ( for: ext) ) . " ,
171
+ message: " \( conjunction) \( incompatibilityDesc) because \( self . description ( for: ext) ) . " ,
167
172
isNumbered: isNumbered
168
173
)
169
174
}
170
175
} else {
171
- self . record (
176
+ try self . record (
172
177
incompatibility,
173
- message: " \( incompatibilityDesc) because \( try self . description ( for: cause. conflict) ) and \( try self . description ( for: cause. other) ) . " ,
178
+ message: " \( incompatibilityDesc) because \( self . description ( for: cause. conflict) ) and \( self . description ( for: cause. other) ) . " ,
174
179
isNumbered: isNumbered
175
180
)
176
181
}
@@ -213,13 +218,16 @@ struct DiagnosticReportBuilder {
213
218
return " package ' \( versionedDependency. identity) ' is required using a stable-version but ' \( versionedDependency. identity) ' depends on an unstable-version package ' \( unversionedDependency. identity) ' "
214
219
case . incompatibleToolsVersion( let version) :
215
220
let term = incompatibility. terms. first!
216
- return " \( try self . description ( for: term, normalizeRange: true ) ) contains incompatible tools version ( \( version) ) "
221
+ return try " \( self . description ( for: term, normalizeRange: true ) ) contains incompatible tools version ( \( version) ) "
217
222
}
218
223
219
224
let terms = incompatibility. terms
220
225
if terms. count == 1 {
221
226
let term = terms. first!
222
- let prefix = try hasEffectivelyAnyRequirement ( term) ? term. node. nameForDiagnostics : self . description ( for: term, normalizeRange: true )
227
+ let prefix = try hasEffectivelyAnyRequirement ( term) ? term. node. nameForDiagnostics : self . description (
228
+ for: term,
229
+ normalizeRange: true
230
+ )
223
231
return " \( prefix) " + ( term. isPositive ? " cannot be used " : " is required " )
224
232
} else if terms. count == 2 {
225
233
let term1 = terms. first!
@@ -233,12 +241,12 @@ struct DiagnosticReportBuilder {
233
241
}
234
242
}
235
243
236
- let positive = try terms. filter ( \. isPositive) . map { try description ( for: $0) }
237
- let negative = try terms. filter { !$0. isPositive } . map { try description ( for: $0) }
244
+ let positive = try terms. filter ( \. isPositive) . map { try self . description ( for: $0) }
245
+ let negative = try terms. filter { !$0. isPositive } . map { try self . description ( for: $0) }
238
246
if !positive. isEmpty, !negative. isEmpty {
239
247
if positive. count == 1 {
240
248
let positiveTerm = terms. first { $0. isPositive } !
241
- return " \( try self . description ( for: positiveTerm, normalizeRange: true ) ) practically depends on \( negative. joined ( separator: " or " ) ) "
249
+ return try " \( self . description ( for: positiveTerm, normalizeRange: true ) ) practically depends on \( negative. joined ( separator: " or " ) ) "
242
250
} else {
243
251
return " if \( positive. joined ( separator: " and " ) ) then \( negative. joined ( separator: " or " ) ) "
244
252
}
@@ -351,8 +359,8 @@ struct DiagnosticReportBuilder {
351
359
}
352
360
}
353
361
354
- private extension DependencyResolutionNode {
355
- var nameForDiagnostics : String {
362
+ extension DependencyResolutionNode {
363
+ fileprivate var nameForDiagnostics : String {
356
364
" ' \( self . package . identity) ' "
357
365
}
358
366
}
0 commit comments