Add descriptions for SwiftSyntax errors (#16339)

This commit is contained in:
Harlan
2018-05-03 14:40:14 -04:00
committed by GitHub
parent ebf12c3e66
commit 405e34e91c
2 changed files with 25 additions and 3 deletions

View File

@@ -22,9 +22,23 @@ import Glibc
/// A list of possible errors that could be encountered while parsing a
/// Syntax tree.
public enum ParserError: Error {
public enum ParserError: Error, CustomStringConvertible {
case swiftcFailed(Int, String)
case invalidFile
public var description: String {
switch self{
case let .swiftcFailed(exitCode, stderr):
let stderrLines = stderr.split(separator: "\n")
return """
swiftc returned with non-zero exit code \(exitCode)
stderr:
\(stderrLines.joined(separator: "\n "))
"""
case .invalidFile:
return "swiftc created an invalid syntax file"
}
}
}
extension Syntax {