mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SwiftSyntax] Add debug print when the JSONDecoder fails to decode JSON (#14056)
from the compiler's '-emit-syntax'. Investigating: rdar://problem/36379512
This commit is contained in:
@@ -25,6 +25,7 @@ import Glibc
|
||||
public enum ParserError: Error {
|
||||
case swiftcFailed(Int, String)
|
||||
case invalidFile
|
||||
case jsonDecodeError(input: String, originalError: Error);
|
||||
}
|
||||
|
||||
extension Syntax {
|
||||
@@ -42,8 +43,16 @@ extension Syntax {
|
||||
guard result.wasSuccessful else {
|
||||
throw ParserError.swiftcFailed(result.exitCode, result.stderr)
|
||||
}
|
||||
let jsonData = result.stdoutData
|
||||
let decoder = JSONDecoder()
|
||||
let raw = try decoder.decode(RawSyntax.self, from: result.stdoutData)
|
||||
let raw: RawSyntax
|
||||
do {
|
||||
raw = try decoder.decode(RawSyntax.self, from: jsonData)
|
||||
} catch let err {
|
||||
throw ParserError.jsonDecodeError(
|
||||
input: String(data: jsonData, encoding: .utf8) ?? jsonData.base64EncodedString(),
|
||||
originalError: err)
|
||||
}
|
||||
guard let file = Syntax.fromRaw(raw) as? SourceFileSyntax else {
|
||||
throw ParserError.invalidFile
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user