@@ -311,8 +311,7 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
311
311
}
312
312
}
313
313
} catch {
314
- results. append ( . init( description: error. localizedDescription, source: source) )
315
- diagnosticEngine. emit ( . init( description: error. localizedDescription, source: source) )
314
+ recordProblem ( from: error, in: & results, withIdentifier: " render-node " )
316
315
}
317
316
}
318
317
}
@@ -327,8 +326,7 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
327
326
do {
328
327
try outputConsumer. consume ( assetsInBundle: bundle)
329
328
} catch {
330
- conversionProblems. append ( . init( description: error. localizedDescription, source: nil ) )
331
- diagnosticEngine. emit ( . init( description: error. localizedDescription, source: nil ) )
329
+ recordProblem ( from: error, in: & conversionProblems, withIdentifier: " assets " )
332
330
}
333
331
334
332
// Write various metadata
@@ -338,17 +336,15 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
338
336
try outputConsumer. consume ( indexingRecords: indexingRecords)
339
337
try outputConsumer. consume ( assets: assets)
340
338
} catch {
341
- conversionProblems. append ( . init( description: error. localizedDescription, source: nil ) )
342
- diagnosticEngine. emit ( . init( description: error. localizedDescription, source: nil ) )
339
+ recordProblem ( from: error, in: & conversionProblems, withIdentifier: " metadata " )
343
340
}
344
341
}
345
342
346
343
if emitDigest {
347
344
do {
348
345
try outputConsumer. consume ( problems: context. problems + conversionProblems)
349
346
} catch {
350
- conversionProblems. append ( . init( description: error. localizedDescription, source: nil ) )
351
- diagnosticEngine. emit ( . init( description: error. localizedDescription, source: nil ) )
347
+ recordProblem ( from: error, in: & conversionProblems, withIdentifier: " problems " )
352
348
}
353
349
}
354
350
@@ -357,9 +353,7 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
357
353
do {
358
354
try outputConsumer. consume ( documentationCoverageInfo: coverageInfo)
359
355
} catch {
360
- let problem = Problem ( description: error. localizedDescription, source: nil )
361
- conversionProblems. append ( problem)
362
- diagnosticEngine. emit ( problem)
356
+ recordProblem ( from: error, in: & conversionProblems, withIdentifier: " coverage " )
363
357
}
364
358
case . none:
365
359
break
@@ -412,6 +406,34 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
412
406
return isDocumentPathToConvert || isExternalIDToConvert
413
407
}
414
408
409
+ /// Record a problem from the given error in the given problem array.
410
+ ///
411
+ /// Creates a ``Problem`` from the given `Error` and identifier, emits it to the
412
+ /// ``DocumentationConverter``'s ``DiagnosticEngine``, and appends it to the given
413
+ /// problem array.
414
+ ///
415
+ /// - Parameters:
416
+ /// - error: The error that describes the problem.
417
+ /// - problems: The array that the created problem should be appended to.
418
+ /// - identifier: A unique identifier the problem.
419
+ private func recordProblem(
420
+ from error: Swift . Error ,
421
+ in problems: inout [ Problem ] ,
422
+ withIdentifier identifier: String
423
+ ) {
424
+ let singleDiagnostic = Diagnostic (
425
+ source: nil ,
426
+ severity: . error,
427
+ range: nil ,
428
+ identifier: " org.swift.docc.documentation-converter. \( identifier) " ,
429
+ summary: error. localizedDescription
430
+ )
431
+ let problem = Problem ( diagnostic: singleDiagnostic, possibleSolutions: [ ] )
432
+
433
+ diagnosticEngine. emit ( problem)
434
+ problems. append ( problem)
435
+ }
436
+
415
437
enum Error : DescribedError {
416
438
case doesNotContainBundle( url: URL )
417
439
@@ -427,21 +449,3 @@ public struct DocumentationConverter: DocumentationConverterProtocol {
427
449
}
428
450
}
429
451
}
430
-
431
- private extension Problem {
432
- /// Creates a new problem with the given description and documentation source location.
433
- ///
434
- /// Use this to provide a user-friendly description of an error,
435
- /// along with a direct reference to the source file and line number where you call this initializer.
436
- ///
437
- /// - Parameters:
438
- /// - description: A brief description of the problem.
439
- /// - source: The URL for the documentation file that caused this problem, if any.
440
- /// - file: The source file where you call this initializer.
441
- init ( description: String , source: URL ? , file: String = #file) {
442
- let fileName = URL ( fileURLWithPath: file) . deletingPathExtension ( ) . lastPathComponent
443
-
444
- let singleDiagnostic = Diagnostic ( source: source, severity: . error, range: nil , identifier: " org.swift.docc. \( fileName) " , summary: description)
445
- self . init ( diagnostic: singleDiagnostic, possibleSolutions: [ ] )
446
- }
447
- }
0 commit comments