func _run_main()

in core/swift53Action/swiftbuild.py.launcher.swift [67:98]


func _run_main<In: Decodable, Out: Encodable>(mainFunction: (In, @escaping (Out?, Error?) -> Void) -> Void, json: Data) {
    do {
        let input = try Whisk.jsonDecoder.decode(In.self, from: json)
        let resultHandler = { (out: Out?, error: Error?) in
            if let error = error {
                _whisk_print_error(message: "Action handler callback returned an error:", error: error)
                return
            }
            guard let out = out else {
                _whisk_print_error(message: "Action handler callback did not return response or error.", error: nil)
                return
            }
            do {
                let jsonData = try Whisk.jsonEncoder.encode(out)
                _whisk_print_result(jsonData: jsonData)
            } catch let error as EncodingError {
                _whisk_print_error(message: "JSONEncoder failed to encode Codable type to JSON string:", error: error)
                return
            } catch {
                _whisk_print_error(message: "Failed to execute action handler with error:", error: error)
                return
            }
        }
        let _ = mainFunction(input, resultHandler)
    } catch let error as DecodingError {
        _whisk_print_error(message: "JSONDecoder failed to decode JSON string \(String(data: json, encoding: .utf8)!.replacingOccurrences(of: "\"", with: "\\\"")) to Codable type:", error: error)
        return
    } catch {
        _whisk_print_error(message: "Failed to execute action handler with error:", error: error)
        return
    }
}