//
//  main.swift
//  quicktype
//
//  Created by Mark Probst on 8/24/17.
//  Copyright © 2017 quicktype. All rights reserved.
//

import Foundation

let filename = CommandLine.arguments[1]
guard let data = FileHandle(forReadingAtPath: filename)?.readDataToEndOfFile()
else {
    print("Error: Could not read input file")
    exit(1)
}

guard let obj = topLevel(fromJSONData: data)
else {
    print("Error: Could not deserialize")
    exit(1)
}

guard let newData = jsonData(fromTopLevel: obj)
else {
    print("Error: Could not deserialize")
    exit(1)
}

guard let jsonString = String(data: newData, encoding: String.Encoding.utf8)
else {
    print("Error: Could not stringify")
    exit(1)
}

print(jsonString)

//
//  main.swift
//  quicktype
//
//  Created by Mark Probst on 8/24/17.
//  Copyright © 2017 quicktype. All rights reserved.
//

import Foundation

let filename = CommandLine.arguments[1]
guard
    let data = FileHandle(forReadingAtPath: filename)?.readDataToEndOfFile(),
    let obj = topLevel(fromJSONData: data),
    let newData = jsonData(fromTopLevel: obj),
    let jsonString = String(data: newData, encoding: String.Encoding.utf8)
else {
    exit(1)
}

print(jsonString)

--- 
+++ 
@@ -9,12 +9,27 @@
 import Foundation
 
 let filename = CommandLine.arguments[1]
-guard
-    let data = FileHandle(forReadingAtPath: filename)?.readDataToEndOfFile(),
-    let obj = topLevel(fromJSONData: data),
-    let newData = jsonData(fromTopLevel: obj),
-    let jsonString = String(data: newData, encoding: String.Encoding.utf8)
+guard let data = FileHandle(forReadingAtPath: filename)?.readDataToEndOfFile()
 else {
+    print("Error: Could not read input file")
+    exit(1)
+}
+
+guard let obj = topLevel(fromJSONData: data)
+else {
+    print("Error: Could not deserialize")
+    exit(1)
+}
+
+guard let newData = jsonData(fromTopLevel: obj)
+else {
+    print("Error: Could not deserialize")
+    exit(1)
+}
+
+guard let jsonString = String(data: newData, encoding: String.Encoding.utf8)
+else {
+    print("Error: Could not stringify")
     exit(1)
 }
 
Print error messages in the swift test driver


Original commit d6b513b0737ae7de37d4fa318a8c581dfaba5c95
