From 1ce77995fa5d623bdef1c28cc560b4c6200ca9a2 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 23 Jan 2023 14:56:22 -0800 Subject: [PATCH 01/13] temp --- packages/pigeon/lib/swift_generator.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index b0aa98d5675..671e97688c8 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -441,6 +441,8 @@ import FlutterMacOS final String messageVarName = method.arguments.isNotEmpty ? 'message' : '_'; indent.addScoped('{ $messageVarName, reply in', '}', () { + // indent.write('do '); + // indent.addScoped('{', '}', () { final List methodArgument = []; if (method.arguments.isNotEmpty) { indent.writeln('let args = message as! [Any?]'); @@ -474,6 +476,10 @@ import FlutterMacOS indent.writeln('reply(wrapResult(result))'); } } + // }, addTrailingNewline: false); + // indent.addScoped(' catch (let error) {', '}', () { + // indent.writeln('reply(wrapError(error))'); + // }); }); }, addTrailingNewline: false); indent.addScoped(' else {', '}', () { @@ -584,6 +590,8 @@ import FlutterMacOS indent.newln(); indent.write('private func wrapError(_ error: FlutterError) -> [Any?] '); indent.addScoped('{', '}', () { + // indent.writeln('print(error)'); + indent.write('return '); indent.addScoped('[', ']', () { indent.writeln('error.code,'); From 4e23f1f69bff0a33cb3f11dc8099b3ecbae1a0b8 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 23 Jan 2023 18:22:41 -0800 Subject: [PATCH 02/13] sets up use of wrapError --- packages/pigeon/lib/swift_generator.dart | 88 +-- .../ios/Classes/CoreTests.gen.swift | 542 +++++++++++------- .../test_plugin/ios/Classes/TestPlugin.swift | 10 +- .../macos/Classes/CoreTests.gen.swift | 542 +++++++++++------- .../pigeon/test/swift_generator_test.dart | 14 +- 5 files changed, 756 insertions(+), 440 deletions(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 671e97688c8..94cce35e217 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -399,12 +399,14 @@ import FlutterMacOS if (method.isAsynchronous) { argSignature.add('completion: @escaping ($returnType) -> Void'); - indent.writeln('func ${method.name}(${argSignature.join(', ')})'); + indent.writeln( + 'func ${method.name}(${argSignature.join(', ')}) throws'); } else if (method.returnType.isVoid) { - indent.writeln('func ${method.name}(${argSignature.join(', ')})'); + indent.writeln( + 'func ${method.name}(${argSignature.join(', ')}) throws'); } else { indent.writeln( - 'func ${method.name}(${argSignature.join(', ')}) -> $returnType'); + 'func ${method.name}(${argSignature.join(', ')}) throws -> $returnType'); } } }); @@ -441,45 +443,45 @@ import FlutterMacOS final String messageVarName = method.arguments.isNotEmpty ? 'message' : '_'; indent.addScoped('{ $messageVarName, reply in', '}', () { - // indent.write('do '); - // indent.addScoped('{', '}', () { - final List methodArgument = []; - if (method.arguments.isNotEmpty) { - indent.writeln('let args = message as! [Any?]'); - enumerate(method.arguments, (int index, NamedType arg) { - final String argName = _getSafeArgumentName(index, arg); - final String argIndex = 'args[$index]'; - indent.writeln( - 'let $argName = ${_castForceUnwrap(argIndex, arg.type, root)}'); - methodArgument.add('${arg.name}: $argName'); - }); - } - final String call = - 'api.${method.name}(${methodArgument.join(', ')})'; - if (method.isAsynchronous) { - indent.write('$call '); - if (method.returnType.isVoid) { - indent.addScoped('{', '}', () { - indent.writeln('reply(wrapResult(nil))'); - }); - } else { - indent.addScoped('{ result in', '}', () { - indent.writeln('reply(wrapResult(result))'); + indent.write('do '); + indent.addScoped('{', '}', () { + final List methodArgument = []; + if (method.arguments.isNotEmpty) { + indent.writeln('let args = message as! [Any?]'); + enumerate(method.arguments, (int index, NamedType arg) { + final String argName = _getSafeArgumentName(index, arg); + final String argIndex = 'args[$index]'; + indent.writeln( + 'let $argName = ${_castForceUnwrap(argIndex, arg.type, root)}'); + methodArgument.add('${arg.name}: $argName'); }); } - } else { - if (method.returnType.isVoid) { - indent.writeln(call); - indent.writeln('reply(wrapResult(nil))'); + final String call = + 'try api.${method.name}(${methodArgument.join(', ')})'; + if (method.isAsynchronous) { + indent.write('$call '); + if (method.returnType.isVoid) { + indent.addScoped('{', '}', () { + indent.writeln('reply(wrapResult(nil))'); + }); + } else { + indent.addScoped('{ result in', '}', () { + indent.writeln('reply(wrapResult(result))'); + }); + } } else { - indent.writeln('let result = $call'); - indent.writeln('reply(wrapResult(result))'); + if (method.returnType.isVoid) { + indent.writeln(call); + indent.writeln('reply(wrapResult(nil))'); + } else { + indent.writeln('let result = $call'); + indent.writeln('reply(wrapResult(result))'); + } } - } - // }, addTrailingNewline: false); - // indent.addScoped(' catch (let error) {', '}', () { - // indent.writeln('reply(wrapError(error))'); - // }); + }, addTrailingNewline: false); + indent.addScoped(' catch {', '}', () { + indent.writeln('reply(wrapError(error))'); + }); }); }, addTrailingNewline: false); indent.addScoped(' else {', '}', () { @@ -588,15 +590,13 @@ import FlutterMacOS void _writeWrapError(Indent indent) { indent.newln(); - indent.write('private func wrapError(_ error: FlutterError) -> [Any?] '); + indent.write('private func wrapError(_ error: Error) -> [Any?] '); indent.addScoped('{', '}', () { - // indent.writeln('print(error)'); - indent.write('return '); indent.addScoped('[', ']', () { - indent.writeln('error.code,'); - indent.writeln('error.message,'); - indent.writeln('error.details'); + indent.writeln('type(of: error),'); + indent.writeln('error,'); + indent.writeln('Thread.callStackSymbols'); }); }); } diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index e1e212adf82..2a45f4d4870 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -20,11 +20,11 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: FlutterError) -> [Any?] { +private func wrapError(_ error: Error) -> [Any?] { return [ - error.code, - error.message, - error.details + type(of: error), + error, + Thread.callStackSymbols ] } @@ -236,67 +236,67 @@ class HostIntegrationCoreApiCodec: FlutterStandardMessageCodec { protocol HostIntegrationCoreApi { /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop() + func noop() throws /// Returns the passed object, to test serialization and deserialization. - func echoAllTypes(everything: AllTypes) -> AllTypes + func echoAllTypes(everything: AllTypes) throws -> AllTypes /// Returns the passed object, to test serialization and deserialization. - func echoAllNullableTypes(everything: AllNullableTypes?) -> AllNullableTypes? + func echoAllNullableTypes(everything: AllNullableTypes?) throws -> AllNullableTypes? /// Returns an error, to test error handling. - func throwError() + func throwError() throws /// Returns passed in int. - func echoInt(anInt: Int32) -> Int32 + func echoInt(anInt: Int32) throws -> Int32 /// Returns passed in double. - func echoDouble(aDouble: Double) -> Double + func echoDouble(aDouble: Double) throws -> Double /// Returns the passed in boolean. - func echoBool(aBool: Bool) -> Bool + func echoBool(aBool: Bool) throws -> Bool /// Returns the passed in string. - func echoString(aString: String) -> String + func echoString(aString: String) throws -> String /// Returns the passed in Uint8List. - func echoUint8List(aUint8List: FlutterStandardTypedData) -> FlutterStandardTypedData + func echoUint8List(aUint8List: FlutterStandardTypedData) throws -> FlutterStandardTypedData /// Returns the passed in generic Object. - func echoObject(anObject: Any) -> Any + func echoObject(anObject: Any) throws -> Any /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func extractNestedNullableString(wrapper: AllNullableTypesWrapper) -> String? + func extractNestedNullableString(wrapper: AllNullableTypesWrapper) throws -> String? /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func createNestedNullableString(nullableString: String?) -> AllNullableTypesWrapper + func createNestedNullableString(nullableString: String?) throws -> AllNullableTypesWrapper /// Returns passed in arguments of multiple types. - func sendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?) -> AllNullableTypes + func sendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?) throws -> AllNullableTypes /// Returns passed in int. - func echoNullableInt(aNullableInt: Int32?) -> Int32? + func echoNullableInt(aNullableInt: Int32?) throws -> Int32? /// Returns passed in double. - func echoNullableDouble(aNullableDouble: Double?) -> Double? + func echoNullableDouble(aNullableDouble: Double?) throws -> Double? /// Returns the passed in boolean. - func echoNullableBool(aNullableBool: Bool?) -> Bool? + func echoNullableBool(aNullableBool: Bool?) throws -> Bool? /// Returns the passed in string. - func echoNullableString(aNullableString: String?) -> String? + func echoNullableString(aNullableString: String?) throws -> String? /// Returns the passed in Uint8List. - func echoNullableUint8List(aNullableUint8List: FlutterStandardTypedData?) -> FlutterStandardTypedData? + func echoNullableUint8List(aNullableUint8List: FlutterStandardTypedData?) throws -> FlutterStandardTypedData? /// Returns the passed in generic Object. - func echoNullableObject(aNullableObject: Any?) -> Any? + func echoNullableObject(aNullableObject: Any?) throws -> Any? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping () -> Void) + func noopAsync(completion: @escaping () -> Void) throws /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) - func callFlutterNoop(completion: @escaping () -> Void) - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) throws + func callFlutterNoop(completion: @escaping () -> Void) throws + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) throws + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) throws + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) throws + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) throws + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) throws + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) throws + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) throws + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) throws + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) throws + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) throws + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) throws + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) throws + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) throws + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) throws + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) throws + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) throws } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -310,8 +310,12 @@ class HostIntegrationCoreApiSetup { let noopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopChannel.setMessageHandler { _, reply in - api.noop() - reply(wrapResult(nil)) + do { + try api.noop() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } } } else { noopChannel.setMessageHandler(nil) @@ -320,10 +324,14 @@ class HostIntegrationCoreApiSetup { let echoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes - let result = api.echoAllTypes(everything: everythingArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + let result = try api.echoAllTypes(everything: everythingArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoAllTypesChannel.setMessageHandler(nil) @@ -332,10 +340,14 @@ class HostIntegrationCoreApiSetup { let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllNullableTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let everythingArg = args[0] as? AllNullableTypes - let result = api.echoAllNullableTypes(everything: everythingArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let everythingArg = args[0] as? AllNullableTypes + let result = try api.echoAllNullableTypes(everything: everythingArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoAllNullableTypesChannel.setMessageHandler(nil) @@ -344,8 +356,12 @@ class HostIntegrationCoreApiSetup { let throwErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwError", binaryMessenger: binaryMessenger, codec: codec) if let api = api { throwErrorChannel.setMessageHandler { _, reply in - api.throwError() - reply(wrapResult(nil)) + do { + try api.throwError() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } } } else { throwErrorChannel.setMessageHandler(nil) @@ -354,10 +370,14 @@ class HostIntegrationCoreApiSetup { let echoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 - let result = api.echoInt(anInt: anIntArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + let result = try api.echoInt(anInt: anIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoIntChannel.setMessageHandler(nil) @@ -366,10 +386,14 @@ class HostIntegrationCoreApiSetup { let echoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double - let result = api.echoDouble(aDouble: aDoubleArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + let result = try api.echoDouble(aDouble: aDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoDoubleChannel.setMessageHandler(nil) @@ -378,10 +402,14 @@ class HostIntegrationCoreApiSetup { let echoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool - let result = api.echoBool(aBool: aBoolArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + let result = try api.echoBool(aBool: aBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoBoolChannel.setMessageHandler(nil) @@ -390,10 +418,14 @@ class HostIntegrationCoreApiSetup { let echoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as! String - let result = api.echoString(aString: aStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as! String + let result = try api.echoString(aString: aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoStringChannel.setMessageHandler(nil) @@ -402,10 +434,14 @@ class HostIntegrationCoreApiSetup { let echoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aUint8ListArg = args[0] as! FlutterStandardTypedData - let result = api.echoUint8List(aUint8List: aUint8ListArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aUint8ListArg = args[0] as! FlutterStandardTypedData + let result = try api.echoUint8List(aUint8List: aUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoUint8ListChannel.setMessageHandler(nil) @@ -414,10 +450,14 @@ class HostIntegrationCoreApiSetup { let echoObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoObjectChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anObjectArg = args[0]! - let result = api.echoObject(anObject: anObjectArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anObjectArg = args[0]! + let result = try api.echoObject(anObject: anObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoObjectChannel.setMessageHandler(nil) @@ -427,10 +467,14 @@ class HostIntegrationCoreApiSetup { let extractNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { extractNestedNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let wrapperArg = args[0] as! AllNullableTypesWrapper - let result = api.extractNestedNullableString(wrapper: wrapperArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let wrapperArg = args[0] as! AllNullableTypesWrapper + let result = try api.extractNestedNullableString(wrapper: wrapperArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { extractNestedNullableStringChannel.setMessageHandler(nil) @@ -440,10 +484,14 @@ class HostIntegrationCoreApiSetup { let createNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { createNestedNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let nullableStringArg = args[0] as? String - let result = api.createNestedNullableString(nullableString: nullableStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let nullableStringArg = args[0] as? String + let result = try api.createNestedNullableString(nullableString: nullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { createNestedNullableStringChannel.setMessageHandler(nil) @@ -452,12 +500,16 @@ class HostIntegrationCoreApiSetup { let sendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sendMultipleNullableTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String - let result = api.sendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + let result = try api.sendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { sendMultipleNullableTypesChannel.setMessageHandler(nil) @@ -466,10 +518,14 @@ class HostIntegrationCoreApiSetup { let echoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableIntArg = args[0] as? Int32 - let result = api.echoNullableInt(aNullableInt: aNullableIntArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableIntArg = args[0] as? Int32 + let result = try api.echoNullableInt(aNullableInt: aNullableIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableIntChannel.setMessageHandler(nil) @@ -478,10 +534,14 @@ class HostIntegrationCoreApiSetup { let echoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableDoubleArg = args[0] as? Double - let result = api.echoNullableDouble(aNullableDouble: aNullableDoubleArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableDoubleArg = args[0] as? Double + let result = try api.echoNullableDouble(aNullableDouble: aNullableDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableDoubleChannel.setMessageHandler(nil) @@ -490,10 +550,14 @@ class HostIntegrationCoreApiSetup { let echoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let result = api.echoNullableBool(aNullableBool: aNullableBoolArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let result = try api.echoNullableBool(aNullableBool: aNullableBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableBoolChannel.setMessageHandler(nil) @@ -502,10 +566,14 @@ class HostIntegrationCoreApiSetup { let echoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableStringArg = args[0] as? String - let result = api.echoNullableString(aNullableString: aNullableStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableStringArg = args[0] as? String + let result = try api.echoNullableString(aNullableString: aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableStringChannel.setMessageHandler(nil) @@ -514,10 +582,14 @@ class HostIntegrationCoreApiSetup { let echoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData - let result = api.echoNullableUint8List(aNullableUint8List: aNullableUint8ListArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData + let result = try api.echoNullableUint8List(aNullableUint8List: aNullableUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableUint8ListChannel.setMessageHandler(nil) @@ -526,10 +598,14 @@ class HostIntegrationCoreApiSetup { let echoNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableObjectChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableObjectArg = args[0] - let result = api.echoNullableObject(aNullableObject: aNullableObjectArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableObjectArg = args[0] + let result = try api.echoNullableObject(aNullableObject: aNullableObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableObjectChannel.setMessageHandler(nil) @@ -539,8 +615,12 @@ class HostIntegrationCoreApiSetup { let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopAsyncChannel.setMessageHandler { _, reply in - api.noopAsync() { - reply(wrapResult(nil)) + do { + try api.noopAsync() { + reply(wrapResult(nil)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -550,10 +630,14 @@ class HostIntegrationCoreApiSetup { let echoAsyncStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAsyncStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as! String - api.echoAsyncString(aString: aStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as! String + try api.echoAsyncString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -562,8 +646,12 @@ class HostIntegrationCoreApiSetup { let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in - api.callFlutterNoop() { - reply(wrapResult(nil)) + do { + try api.callFlutterNoop() { + reply(wrapResult(nil)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -572,10 +660,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoAllTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes - api.callFlutterEchoAllTypes(everything: everythingArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + try api.callFlutterEchoAllTypes(everything: everythingArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -584,12 +676,16 @@ class HostIntegrationCoreApiSetup { let callFlutterSendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterSendMultipleNullableTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String - api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + try api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -598,10 +694,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool - api.callFlutterEchoBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + try api.callFlutterEchoBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -610,10 +710,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 - api.callFlutterEchoInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + try api.callFlutterEchoInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -622,10 +726,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double - api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + try api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -634,10 +742,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as! String - api.callFlutterEchoString(aString: aStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as! String + try api.callFlutterEchoString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -646,10 +758,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - api.callFlutterEchoUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as! FlutterStandardTypedData + try api.callFlutterEchoUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -658,10 +774,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.callFlutterEchoList(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as! [Any?] + try api.callFlutterEchoList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -670,10 +790,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoMapChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aMapArg = args[0] as! [String?: Any?] - api.callFlutterEchoMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aMapArg = args[0] as! [String?: Any?] + try api.callFlutterEchoMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -682,10 +806,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aBoolArg = args[0] as? Bool - api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aBoolArg = args[0] as? Bool + try api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -694,10 +822,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anIntArg = args[0] as? Int32 - api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anIntArg = args[0] as? Int32 + try api.callFlutterEchoNullableInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -706,10 +838,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aDoubleArg = args[0] as? Double - api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aDoubleArg = args[0] as? Double + try api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -718,10 +854,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as? String - api.callFlutterEchoNullableString(aString: aStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as? String + try api.callFlutterEchoNullableString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -730,10 +870,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as? FlutterStandardTypedData - api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as? FlutterStandardTypedData + try api.callFlutterEchoNullableUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -742,10 +886,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as? [Any?] - api.callFlutterEchoNullableList(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as? [Any?] + try api.callFlutterEchoNullableList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -754,10 +902,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aMapArg = args[0] as? [String?: Any?] - api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aMapArg = args[0] as? [String?: Any?] + try api.callFlutterEchoNullableMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -974,7 +1126,7 @@ class FlutterIntegrationCoreApi { /// /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol HostTrivialApi { - func noop() + func noop() throws } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -985,8 +1137,12 @@ class HostTrivialApiSetup { let noopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostTrivialApi.noop", binaryMessenger: binaryMessenger) if let api = api { noopChannel.setMessageHandler { _, reply in - api.noop() - reply(wrapResult(nil)) + do { + try api.noop() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } } } else { noopChannel.setMessageHandler(nil) diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index 3515e4914b4..2b26b89dd93 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -24,6 +24,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { // MARK: HostIntegrationCoreApi implementation func noop() { + } func echoAllTypes(everything: AllTypes) -> AllTypes { @@ -34,9 +35,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return everything } - func throwError() { - // TODO(stuartmorgan): Implement this. See - // https://github.com/flutter/flutter/issues/112483 + func throwError() throws { + throw(errType.thrownErrow) } func echoInt(anInt: Int32) -> Int32 { @@ -189,3 +189,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } } } + +enum errType: Error { + case thrownErrow +} \ No newline at end of file diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index e1e212adf82..2a45f4d4870 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -20,11 +20,11 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: FlutterError) -> [Any?] { +private func wrapError(_ error: Error) -> [Any?] { return [ - error.code, - error.message, - error.details + type(of: error), + error, + Thread.callStackSymbols ] } @@ -236,67 +236,67 @@ class HostIntegrationCoreApiCodec: FlutterStandardMessageCodec { protocol HostIntegrationCoreApi { /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop() + func noop() throws /// Returns the passed object, to test serialization and deserialization. - func echoAllTypes(everything: AllTypes) -> AllTypes + func echoAllTypes(everything: AllTypes) throws -> AllTypes /// Returns the passed object, to test serialization and deserialization. - func echoAllNullableTypes(everything: AllNullableTypes?) -> AllNullableTypes? + func echoAllNullableTypes(everything: AllNullableTypes?) throws -> AllNullableTypes? /// Returns an error, to test error handling. - func throwError() + func throwError() throws /// Returns passed in int. - func echoInt(anInt: Int32) -> Int32 + func echoInt(anInt: Int32) throws -> Int32 /// Returns passed in double. - func echoDouble(aDouble: Double) -> Double + func echoDouble(aDouble: Double) throws -> Double /// Returns the passed in boolean. - func echoBool(aBool: Bool) -> Bool + func echoBool(aBool: Bool) throws -> Bool /// Returns the passed in string. - func echoString(aString: String) -> String + func echoString(aString: String) throws -> String /// Returns the passed in Uint8List. - func echoUint8List(aUint8List: FlutterStandardTypedData) -> FlutterStandardTypedData + func echoUint8List(aUint8List: FlutterStandardTypedData) throws -> FlutterStandardTypedData /// Returns the passed in generic Object. - func echoObject(anObject: Any) -> Any + func echoObject(anObject: Any) throws -> Any /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func extractNestedNullableString(wrapper: AllNullableTypesWrapper) -> String? + func extractNestedNullableString(wrapper: AllNullableTypesWrapper) throws -> String? /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - func createNestedNullableString(nullableString: String?) -> AllNullableTypesWrapper + func createNestedNullableString(nullableString: String?) throws -> AllNullableTypesWrapper /// Returns passed in arguments of multiple types. - func sendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?) -> AllNullableTypes + func sendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?) throws -> AllNullableTypes /// Returns passed in int. - func echoNullableInt(aNullableInt: Int32?) -> Int32? + func echoNullableInt(aNullableInt: Int32?) throws -> Int32? /// Returns passed in double. - func echoNullableDouble(aNullableDouble: Double?) -> Double? + func echoNullableDouble(aNullableDouble: Double?) throws -> Double? /// Returns the passed in boolean. - func echoNullableBool(aNullableBool: Bool?) -> Bool? + func echoNullableBool(aNullableBool: Bool?) throws -> Bool? /// Returns the passed in string. - func echoNullableString(aNullableString: String?) -> String? + func echoNullableString(aNullableString: String?) throws -> String? /// Returns the passed in Uint8List. - func echoNullableUint8List(aNullableUint8List: FlutterStandardTypedData?) -> FlutterStandardTypedData? + func echoNullableUint8List(aNullableUint8List: FlutterStandardTypedData?) throws -> FlutterStandardTypedData? /// Returns the passed in generic Object. - func echoNullableObject(aNullableObject: Any?) -> Any? + func echoNullableObject(aNullableObject: Any?) throws -> Any? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping () -> Void) + func noopAsync(completion: @escaping () -> Void) throws /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) - func callFlutterNoop(completion: @escaping () -> Void) - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) throws + func callFlutterNoop(completion: @escaping () -> Void) throws + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) throws + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) throws + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) throws + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) throws + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) throws + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) throws + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) throws + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) throws + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) throws + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) throws + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) throws + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) throws + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) throws + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) throws + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) throws + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) throws } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -310,8 +310,12 @@ class HostIntegrationCoreApiSetup { let noopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopChannel.setMessageHandler { _, reply in - api.noop() - reply(wrapResult(nil)) + do { + try api.noop() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } } } else { noopChannel.setMessageHandler(nil) @@ -320,10 +324,14 @@ class HostIntegrationCoreApiSetup { let echoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes - let result = api.echoAllTypes(everything: everythingArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + let result = try api.echoAllTypes(everything: everythingArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoAllTypesChannel.setMessageHandler(nil) @@ -332,10 +340,14 @@ class HostIntegrationCoreApiSetup { let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllNullableTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let everythingArg = args[0] as? AllNullableTypes - let result = api.echoAllNullableTypes(everything: everythingArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let everythingArg = args[0] as? AllNullableTypes + let result = try api.echoAllNullableTypes(everything: everythingArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoAllNullableTypesChannel.setMessageHandler(nil) @@ -344,8 +356,12 @@ class HostIntegrationCoreApiSetup { let throwErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwError", binaryMessenger: binaryMessenger, codec: codec) if let api = api { throwErrorChannel.setMessageHandler { _, reply in - api.throwError() - reply(wrapResult(nil)) + do { + try api.throwError() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } } } else { throwErrorChannel.setMessageHandler(nil) @@ -354,10 +370,14 @@ class HostIntegrationCoreApiSetup { let echoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 - let result = api.echoInt(anInt: anIntArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + let result = try api.echoInt(anInt: anIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoIntChannel.setMessageHandler(nil) @@ -366,10 +386,14 @@ class HostIntegrationCoreApiSetup { let echoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double - let result = api.echoDouble(aDouble: aDoubleArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + let result = try api.echoDouble(aDouble: aDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoDoubleChannel.setMessageHandler(nil) @@ -378,10 +402,14 @@ class HostIntegrationCoreApiSetup { let echoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool - let result = api.echoBool(aBool: aBoolArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + let result = try api.echoBool(aBool: aBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoBoolChannel.setMessageHandler(nil) @@ -390,10 +418,14 @@ class HostIntegrationCoreApiSetup { let echoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as! String - let result = api.echoString(aString: aStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as! String + let result = try api.echoString(aString: aStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoStringChannel.setMessageHandler(nil) @@ -402,10 +434,14 @@ class HostIntegrationCoreApiSetup { let echoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aUint8ListArg = args[0] as! FlutterStandardTypedData - let result = api.echoUint8List(aUint8List: aUint8ListArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aUint8ListArg = args[0] as! FlutterStandardTypedData + let result = try api.echoUint8List(aUint8List: aUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoUint8ListChannel.setMessageHandler(nil) @@ -414,10 +450,14 @@ class HostIntegrationCoreApiSetup { let echoObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoObjectChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anObjectArg = args[0]! - let result = api.echoObject(anObject: anObjectArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anObjectArg = args[0]! + let result = try api.echoObject(anObject: anObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoObjectChannel.setMessageHandler(nil) @@ -427,10 +467,14 @@ class HostIntegrationCoreApiSetup { let extractNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { extractNestedNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let wrapperArg = args[0] as! AllNullableTypesWrapper - let result = api.extractNestedNullableString(wrapper: wrapperArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let wrapperArg = args[0] as! AllNullableTypesWrapper + let result = try api.extractNestedNullableString(wrapper: wrapperArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { extractNestedNullableStringChannel.setMessageHandler(nil) @@ -440,10 +484,14 @@ class HostIntegrationCoreApiSetup { let createNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { createNestedNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let nullableStringArg = args[0] as? String - let result = api.createNestedNullableString(nullableString: nullableStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let nullableStringArg = args[0] as? String + let result = try api.createNestedNullableString(nullableString: nullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { createNestedNullableStringChannel.setMessageHandler(nil) @@ -452,12 +500,16 @@ class HostIntegrationCoreApiSetup { let sendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sendMultipleNullableTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String - let result = api.sendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + let result = try api.sendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { sendMultipleNullableTypesChannel.setMessageHandler(nil) @@ -466,10 +518,14 @@ class HostIntegrationCoreApiSetup { let echoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableIntArg = args[0] as? Int32 - let result = api.echoNullableInt(aNullableInt: aNullableIntArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableIntArg = args[0] as? Int32 + let result = try api.echoNullableInt(aNullableInt: aNullableIntArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableIntChannel.setMessageHandler(nil) @@ -478,10 +534,14 @@ class HostIntegrationCoreApiSetup { let echoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableDoubleArg = args[0] as? Double - let result = api.echoNullableDouble(aNullableDouble: aNullableDoubleArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableDoubleArg = args[0] as? Double + let result = try api.echoNullableDouble(aNullableDouble: aNullableDoubleArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableDoubleChannel.setMessageHandler(nil) @@ -490,10 +550,14 @@ class HostIntegrationCoreApiSetup { let echoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let result = api.echoNullableBool(aNullableBool: aNullableBoolArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let result = try api.echoNullableBool(aNullableBool: aNullableBoolArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableBoolChannel.setMessageHandler(nil) @@ -502,10 +566,14 @@ class HostIntegrationCoreApiSetup { let echoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableStringArg = args[0] as? String - let result = api.echoNullableString(aNullableString: aNullableStringArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableStringArg = args[0] as? String + let result = try api.echoNullableString(aNullableString: aNullableStringArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableStringChannel.setMessageHandler(nil) @@ -514,10 +582,14 @@ class HostIntegrationCoreApiSetup { let echoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData - let result = api.echoNullableUint8List(aNullableUint8List: aNullableUint8ListArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData + let result = try api.echoNullableUint8List(aNullableUint8List: aNullableUint8ListArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableUint8ListChannel.setMessageHandler(nil) @@ -526,10 +598,14 @@ class HostIntegrationCoreApiSetup { let echoNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableObjectChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableObjectArg = args[0] - let result = api.echoNullableObject(aNullableObject: aNullableObjectArg) - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableObjectArg = args[0] + let result = try api.echoNullableObject(aNullableObject: aNullableObjectArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } } } else { echoNullableObjectChannel.setMessageHandler(nil) @@ -539,8 +615,12 @@ class HostIntegrationCoreApiSetup { let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopAsyncChannel.setMessageHandler { _, reply in - api.noopAsync() { - reply(wrapResult(nil)) + do { + try api.noopAsync() { + reply(wrapResult(nil)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -550,10 +630,14 @@ class HostIntegrationCoreApiSetup { let echoAsyncStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAsyncStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as! String - api.echoAsyncString(aString: aStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as! String + try api.echoAsyncString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -562,8 +646,12 @@ class HostIntegrationCoreApiSetup { let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in - api.callFlutterNoop() { - reply(wrapResult(nil)) + do { + try api.callFlutterNoop() { + reply(wrapResult(nil)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -572,10 +660,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoAllTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes - api.callFlutterEchoAllTypes(everything: everythingArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + try api.callFlutterEchoAllTypes(everything: everythingArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -584,12 +676,16 @@ class HostIntegrationCoreApiSetup { let callFlutterSendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterSendMultipleNullableTypesChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String - api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + try api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -598,10 +694,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool - api.callFlutterEchoBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + try api.callFlutterEchoBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -610,10 +710,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 - api.callFlutterEchoInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + try api.callFlutterEchoInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -622,10 +726,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double - api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + try api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -634,10 +742,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as! String - api.callFlutterEchoString(aString: aStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as! String + try api.callFlutterEchoString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -646,10 +758,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - api.callFlutterEchoUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as! FlutterStandardTypedData + try api.callFlutterEchoUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -658,10 +774,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - api.callFlutterEchoList(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as! [Any?] + try api.callFlutterEchoList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -670,10 +790,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoMapChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aMapArg = args[0] as! [String?: Any?] - api.callFlutterEchoMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aMapArg = args[0] as! [String?: Any?] + try api.callFlutterEchoMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -682,10 +806,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aBoolArg = args[0] as? Bool - api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aBoolArg = args[0] as? Bool + try api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -694,10 +822,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let anIntArg = args[0] as? Int32 - api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let anIntArg = args[0] as? Int32 + try api.callFlutterEchoNullableInt(anInt: anIntArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -706,10 +838,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aDoubleArg = args[0] as? Double - api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aDoubleArg = args[0] as? Double + try api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -718,10 +854,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aStringArg = args[0] as? String - api.callFlutterEchoNullableString(aString: aStringArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aStringArg = args[0] as? String + try api.callFlutterEchoNullableString(aString: aStringArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -730,10 +870,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as? FlutterStandardTypedData - api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as? FlutterStandardTypedData + try api.callFlutterEchoNullableUint8List(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -742,10 +886,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aListArg = args[0] as? [Any?] - api.callFlutterEchoNullableList(aList: aListArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aListArg = args[0] as? [Any?] + try api.callFlutterEchoNullableList(aList: aListArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -754,10 +902,14 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in - let args = message as! [Any?] - let aMapArg = args[0] as? [String?: Any?] - api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + do { + let args = message as! [Any?] + let aMapArg = args[0] as? [String?: Any?] + try api.callFlutterEchoNullableMap(aMap: aMapArg) { result in + reply(wrapResult(result)) + } + } catch { + reply(wrapError(error)) } } } else { @@ -974,7 +1126,7 @@ class FlutterIntegrationCoreApi { /// /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol HostTrivialApi { - func noop() + func noop() throws } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -985,8 +1137,12 @@ class HostTrivialApiSetup { let noopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostTrivialApi.noop", binaryMessenger: binaryMessenger) if let api = api { noopChannel.setMessageHandler { _, reply in - api.noop() - reply(wrapResult(nil)) + do { + try api.noop() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } } } else { noopChannel.setMessageHandler(nil) diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 1bf859461be..3cd52d3e1e4 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -340,8 +340,8 @@ void main() { const SwiftGenerator generator = SwiftGenerator(); generator.generate(swiftOptions, root, sink); final String code = sink.toString(); - expect(code, contains('func doSomething() -> Output')); - expect(code, contains('let result = api.doSomething()')); + expect(code, contains('func doSomething() throws -> Output')); + expect(code, contains('let result = try api.doSomething()')); expect(code, contains('reply(wrapResult(result))')); }); @@ -737,8 +737,8 @@ void main() { const SwiftGenerator generator = SwiftGenerator(); generator.generate(swiftOptions, root, sink); final String code = sink.toString(); - expect(code, contains('func doit() -> [Int32?]')); - expect(code, contains('let result = api.doit()')); + expect(code, contains('func doit() throws -> [Int32?]')); + expect(code, contains('let result = try api.doit()')); expect(code, contains('reply(wrapResult(result))')); }); @@ -795,11 +795,11 @@ void main() { const SwiftGenerator generator = SwiftGenerator(); generator.generate(swiftOptions, root, sink); final String code = sink.toString(); - expect(code, contains('func add(x: Int32, y: Int32) -> Int32')); + expect(code, contains('func add(x: Int32, y: Int32) throws -> Int32')); expect(code, contains('let args = message as! [Any?]')); expect(code, contains('let xArg = args[0] as! Int32')); expect(code, contains('let yArg = args[1] as! Int32')); - expect(code, contains('let result = api.add(x: xArg, y: yArg)')); + expect(code, contains('let result = try api.add(x: xArg, y: yArg)')); expect(code, contains('reply(wrapResult(result))')); }); @@ -859,7 +859,7 @@ void main() { const SwiftGenerator generator = SwiftGenerator(); generator.generate(swiftOptions, root, sink); final String code = sink.toString(); - expect(code, contains('func doit() -> Int32?')); + expect(code, contains('func doit() throws -> Int32?')); }); test('return nullable host async', () { From c8aed8f8c9f525893c474a7c913bfdea6e0403f7 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 23 Jan 2023 19:27:07 -0800 Subject: [PATCH 03/13] remove swift from skip list, update wrapError func --- packages/pigeon/lib/swift_generator.dart | 6 +++--- .../shared_test_plugin_code/lib/integration_tests.dart | 5 +---- .../test_plugin/ios/Classes/CoreTests.gen.swift | 6 +++--- .../test_plugin/macos/Classes/CoreTests.gen.swift | 6 +++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 94cce35e217..acc2567f487 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -594,9 +594,9 @@ import FlutterMacOS indent.addScoped('{', '}', () { indent.write('return '); indent.addScoped('[', ']', () { - indent.writeln('type(of: error),'); - indent.writeln('error,'); - indent.writeln('Thread.callStackSymbols'); + indent.writeln(r'"\(type(of: error))",'); + indent.writeln(r'"\(error)",'); + indent.writeln(r'"\(Thread.callStackSymbols)"'); }); }); } diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index 87bc7187e20..78aa5a87e7b 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -231,10 +231,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(() async { await api.throwError(); }, throwsA(isA())); - }, - // Currently unimplementable for Swift: - // https://github.com/flutter/flutter/issues/112483 - skip: targetGenerator == TargetGenerator.swift); + }); testWidgets('nested objects can be sent correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 2a45f4d4870..81125d3d442 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -22,9 +22,9 @@ private func wrapResult(_ result: Any?) -> [Any?] { private func wrapError(_ error: Error) -> [Any?] { return [ - type(of: error), - error, - Thread.callStackSymbols + "\(type(of: error))", + "\(error)", + "\(Thread.callStackSymbols)" ] } diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 2a45f4d4870..81125d3d442 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -22,9 +22,9 @@ private func wrapResult(_ result: Any?) -> [Any?] { private func wrapError(_ error: Error) -> [Any?] { return [ - type(of: error), - error, - Thread.callStackSymbols + "\(type(of: error))", + "\(error)", + "\(Thread.callStackSymbols)" ] } From 93e2062a6ae71734ca547aa3d497c8a6da196a25 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 23 Jan 2023 19:30:51 -0800 Subject: [PATCH 04/13] changelog --- packages/pigeon/CHANGELOG.md | 4 ++++ packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/mock_handler_tester/test/message.dart | 2 +- packages/pigeon/mock_handler_tester/test/test.dart | 2 +- .../com/example/alternate_language_test_plugin/CoreTests.java | 2 +- .../ios/Classes/CoreTests.gen.h | 2 +- .../ios/Classes/CoreTests.gen.m | 2 +- .../flutter_null_safe_unit_tests/lib/core_tests.gen.dart | 2 +- .../lib/flutter_unittests.gen.dart | 2 +- .../flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart | 2 +- .../flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart | 2 +- .../flutter_null_safe_unit_tests/lib/null_fields.gen.dart | 2 +- .../lib/nullable_returns.gen.dart | 2 +- .../flutter_null_safe_unit_tests/lib/primitive.gen.dart | 2 +- .../lib/src/generated/core_tests.gen.dart | 2 +- .../src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt | 2 +- .../test_plugin/ios/Classes/CoreTests.gen.swift | 2 +- .../test_plugin/macos/Classes/CoreTests.gen.swift | 2 +- .../test_plugin/windows/pigeon/core_tests.gen.cpp | 2 +- .../test_plugin/windows/pigeon/core_tests.gen.h | 2 +- packages/pigeon/pubspec.yaml | 2 +- 21 files changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index a1f08b14b45..13085a5a67c 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 7.0.5 + +* [swift] Adds error handling to sync host api methods. + ## 7.0.4 * [c++] Fixes minor output formatting issues. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 2e4918e0b62..ccc7326749b 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -11,7 +11,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '7.0.4'; +const String pigeonVersion = '7.0.5'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index 7350cbb3caf..9cd02367e12 100644 --- a/packages/pigeon/mock_handler_tester/test/message.dart +++ b/packages/pigeon/mock_handler_tester/test/message.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index 66709311771..152a0763473 100644 --- a/packages/pigeon/mock_handler_tester/test/test.dart +++ b/packages/pigeon/mock_handler_tester/test/test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index 0edb5fa1eb6..7e4d7ae9964 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.alternate_language_test_plugin; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 286e4c59cff..b7001f492f1 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #import diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index 4df83cf8c5b..cae5ac34080 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "CoreTests.gen.h" diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index d3638f41859..6fb1023d19b 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart index 1ba2ba65cc3..8b416c495ff 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart index b2c5fa3ee94..1d0d98e53b1 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart index 85433f0bc13..aea9caa9c95 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart index 8d62f3199da..ee30169b714 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart index 1c6e264823e..9e2d4b6ddae 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart index 9e50dfd802f..0051028506f 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.3), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index 93caa8f00f3..6fb1023d19b 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index 1db2367c5ce..d4eaaef4d47 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.test_plugin diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 207ece4fc82..05a549889b2 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 207ece4fc82..05a549889b2 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index 4cba3236327..e1c00cc1002 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index d696b510430..68a2397261c 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.4), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_CORE_TESTS_GEN_H_ diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index ad4be28a5ac..b1f09af218b 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 7.0.4 # This must match the version in lib/generator_tools.dart +version: 7.0.5 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" From adfaa8f83507e90934037413ff121ec3a6d84ec5 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Mon, 23 Jan 2023 20:38:45 -0800 Subject: [PATCH 05/13] macos tests --- .../test_plugin/macos/Classes/TestPlugin.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 74614735afd..12e9cd90573 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -34,9 +34,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return everything } - func throwError() { - // TODO(stuartmorgan): Implement this. See - // https://github.com/flutter/flutter/issues/112483 + func throwError() throws { + throw(errType.thrownErrow) } func echoInt(anInt: Int32) -> Int32 { @@ -189,3 +188,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } } } + +enum errType: Error { + case thrownErrow +} \ No newline at end of file From 7263a0588cf844d6980a176d6d269a842d2fac5b Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 24 Jan 2023 10:31:47 -0800 Subject: [PATCH 06/13] Stacktrace label --- packages/pigeon/lib/swift_generator.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index acc2567f487..0bceac5cff0 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -596,7 +596,7 @@ import FlutterMacOS indent.addScoped('[', ']', () { indent.writeln(r'"\(type(of: error))",'); indent.writeln(r'"\(error)",'); - indent.writeln(r'"\(Thread.callStackSymbols)"'); + indent.writeln(r'"Stacktrace: \(Thread.callStackSymbols)"'); }); }); } From 091149fab7fcdcfd39ee4269608864a5235c52dd Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 25 Jan 2023 11:04:30 -0800 Subject: [PATCH 07/13] nits --- packages/pigeon/lib/swift_generator.dart | 2 +- .../test_plugin/ios/Classes/CoreTests.gen.swift | 4 ++-- .../platform_tests/test_plugin/ios/Classes/TestPlugin.swift | 2 +- .../test_plugin/macos/Classes/CoreTests.gen.swift | 4 ++-- .../platform_tests/test_plugin/macos/Classes/TestPlugin.swift | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 0bceac5cff0..005f1575d46 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -594,8 +594,8 @@ import FlutterMacOS indent.addScoped('{', '}', () { indent.write('return '); indent.addScoped('[', ']', () { - indent.writeln(r'"\(type(of: error))",'); indent.writeln(r'"\(error)",'); + indent.writeln(r'"\(type(of: error))",'); indent.writeln(r'"Stacktrace: \(Thread.callStackSymbols)"'); }); }); diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 05a549889b2..8c05ef48fae 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -22,9 +22,9 @@ private func wrapResult(_ result: Any?) -> [Any?] { private func wrapError(_ error: Error) -> [Any?] { return [ - "\(type(of: error))", "\(error)", - "\(Thread.callStackSymbols)" + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" ] } diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index 2b26b89dd93..14fb5fad285 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -36,7 +36,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw(errType.thrownErrow) + throw errType.thrownErrow } func echoInt(anInt: Int32) -> Int32 { diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 05a549889b2..8c05ef48fae 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -22,9 +22,9 @@ private func wrapResult(_ result: Any?) -> [Any?] { private func wrapError(_ error: Error) -> [Any?] { return [ - "\(type(of: error))", "\(error)", - "\(Thread.callStackSymbols)" + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" ] } diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 12e9cd90573..adca55554ad 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -35,7 +35,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw(errType.thrownErrow) + throw errType.thrownErrow } func echoInt(anInt: Int32) -> Int32 { From 9879218569d9f8e6d8fee3570567299b9a06ff14 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 25 Jan 2023 15:44:21 -0800 Subject: [PATCH 08/13] async wont try, do, throw, or catch --- packages/pigeon/lib/swift_generator.dart | 64 ++-- .../ios/Classes/CoreTests.gen.swift | 334 +++++++----------- .../macos/Classes/CoreTests.gen.swift | 334 +++++++----------- 3 files changed, 290 insertions(+), 442 deletions(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 005f1575d46..63ec7b74f46 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -399,8 +399,7 @@ import FlutterMacOS if (method.isAsynchronous) { argSignature.add('completion: @escaping ($returnType) -> Void'); - indent.writeln( - 'func ${method.name}(${argSignature.join(', ')}) throws'); + indent.writeln('func ${method.name}(${argSignature.join(', ')})'); } else if (method.returnType.isVoid) { indent.writeln( 'func ${method.name}(${argSignature.join(', ')}) throws'); @@ -443,33 +442,34 @@ import FlutterMacOS final String messageVarName = method.arguments.isNotEmpty ? 'message' : '_'; indent.addScoped('{ $messageVarName, reply in', '}', () { - indent.write('do '); - indent.addScoped('{', '}', () { - final List methodArgument = []; - if (method.arguments.isNotEmpty) { - indent.writeln('let args = message as! [Any?]'); - enumerate(method.arguments, (int index, NamedType arg) { - final String argName = _getSafeArgumentName(index, arg); - final String argIndex = 'args[$index]'; - indent.writeln( - 'let $argName = ${_castForceUnwrap(argIndex, arg.type, root)}'); - methodArgument.add('${arg.name}: $argName'); + final List methodArgument = []; + if (method.arguments.isNotEmpty) { + indent.writeln('let args = message as! [Any?]'); + enumerate(method.arguments, (int index, NamedType arg) { + final String argName = _getSafeArgumentName(index, arg); + final String argIndex = 'args[$index]'; + indent.writeln( + 'let $argName = ${_castForceUnwrap(argIndex, arg.type, root)}'); + methodArgument.add('${arg.name}: $argName'); + }); + } + final String tryStatement = method.isAsynchronous ? '' : 'try '; + final String call = + '${tryStatement}api.${method.name}(${methodArgument.join(', ')})'; + if (method.isAsynchronous) { + indent.write('$call '); + if (method.returnType.isVoid) { + indent.addScoped('{', '}', () { + indent.writeln('reply(wrapResult(nil))'); }); - } - final String call = - 'try api.${method.name}(${methodArgument.join(', ')})'; - if (method.isAsynchronous) { - indent.write('$call '); - if (method.returnType.isVoid) { - indent.addScoped('{', '}', () { - indent.writeln('reply(wrapResult(nil))'); - }); - } else { - indent.addScoped('{ result in', '}', () { - indent.writeln('reply(wrapResult(result))'); - }); - } } else { + indent.addScoped('{ result in', '}', () { + indent.writeln('reply(wrapResult(result))'); + }); + } + } else { + indent.write('do '); + indent.addScoped('{', '}', () { if (method.returnType.isVoid) { indent.writeln(call); indent.writeln('reply(wrapResult(nil))'); @@ -477,11 +477,11 @@ import FlutterMacOS indent.writeln('let result = $call'); indent.writeln('reply(wrapResult(result))'); } - } - }, addTrailingNewline: false); - indent.addScoped(' catch {', '}', () { - indent.writeln('reply(wrapError(error))'); - }); + }, addTrailingNewline: false); + indent.addScoped(' catch {', '}', () { + indent.writeln('reply(wrapError(error))'); + }); + } }); }, addTrailingNewline: false); indent.addScoped(' else {', '}', () { diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 8c05ef48fae..cc724052894 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -277,26 +277,26 @@ protocol HostIntegrationCoreApi { func echoNullableObject(aNullableObject: Any?) throws -> Any? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping () -> Void) throws + func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) throws - func callFlutterNoop(completion: @escaping () -> Void) throws - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) throws - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) throws - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) throws - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) throws - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) throws - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) throws - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) throws - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) throws - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) throws - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) throws - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) throws - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) throws - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) throws - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) throws - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) throws - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) throws + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) + func callFlutterNoop(completion: @escaping () -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -324,9 +324,9 @@ class HostIntegrationCoreApiSetup { let echoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes do { - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes let result = try api.echoAllTypes(everything: everythingArg) reply(wrapResult(result)) } catch { @@ -340,9 +340,9 @@ class HostIntegrationCoreApiSetup { let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllNullableTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let everythingArg = args[0] as? AllNullableTypes do { - let args = message as! [Any?] - let everythingArg = args[0] as? AllNullableTypes let result = try api.echoAllNullableTypes(everything: everythingArg) reply(wrapResult(result)) } catch { @@ -370,9 +370,9 @@ class HostIntegrationCoreApiSetup { let echoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 do { - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 let result = try api.echoInt(anInt: anIntArg) reply(wrapResult(result)) } catch { @@ -386,9 +386,9 @@ class HostIntegrationCoreApiSetup { let echoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double do { - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double let result = try api.echoDouble(aDouble: aDoubleArg) reply(wrapResult(result)) } catch { @@ -402,9 +402,9 @@ class HostIntegrationCoreApiSetup { let echoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool do { - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool let result = try api.echoBool(aBool: aBoolArg) reply(wrapResult(result)) } catch { @@ -418,9 +418,9 @@ class HostIntegrationCoreApiSetup { let echoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as! String do { - let args = message as! [Any?] - let aStringArg = args[0] as! String let result = try api.echoString(aString: aStringArg) reply(wrapResult(result)) } catch { @@ -434,9 +434,9 @@ class HostIntegrationCoreApiSetup { let echoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aUint8ListArg = args[0] as! FlutterStandardTypedData do { - let args = message as! [Any?] - let aUint8ListArg = args[0] as! FlutterStandardTypedData let result = try api.echoUint8List(aUint8List: aUint8ListArg) reply(wrapResult(result)) } catch { @@ -450,9 +450,9 @@ class HostIntegrationCoreApiSetup { let echoObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anObjectArg = args[0]! do { - let args = message as! [Any?] - let anObjectArg = args[0]! let result = try api.echoObject(anObject: anObjectArg) reply(wrapResult(result)) } catch { @@ -467,9 +467,9 @@ class HostIntegrationCoreApiSetup { let extractNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { extractNestedNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let wrapperArg = args[0] as! AllNullableTypesWrapper do { - let args = message as! [Any?] - let wrapperArg = args[0] as! AllNullableTypesWrapper let result = try api.extractNestedNullableString(wrapper: wrapperArg) reply(wrapResult(result)) } catch { @@ -484,9 +484,9 @@ class HostIntegrationCoreApiSetup { let createNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { createNestedNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let nullableStringArg = args[0] as? String do { - let args = message as! [Any?] - let nullableStringArg = args[0] as? String let result = try api.createNestedNullableString(nullableString: nullableStringArg) reply(wrapResult(result)) } catch { @@ -500,11 +500,11 @@ class HostIntegrationCoreApiSetup { let sendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sendMultipleNullableTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String do { - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String let result = try api.sendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) reply(wrapResult(result)) } catch { @@ -518,9 +518,9 @@ class HostIntegrationCoreApiSetup { let echoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableIntArg = args[0] as? Int32 do { - let args = message as! [Any?] - let aNullableIntArg = args[0] as? Int32 let result = try api.echoNullableInt(aNullableInt: aNullableIntArg) reply(wrapResult(result)) } catch { @@ -534,9 +534,9 @@ class HostIntegrationCoreApiSetup { let echoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableDoubleArg = args[0] as? Double do { - let args = message as! [Any?] - let aNullableDoubleArg = args[0] as? Double let result = try api.echoNullableDouble(aNullableDouble: aNullableDoubleArg) reply(wrapResult(result)) } catch { @@ -550,9 +550,9 @@ class HostIntegrationCoreApiSetup { let echoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool do { - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool let result = try api.echoNullableBool(aNullableBool: aNullableBoolArg) reply(wrapResult(result)) } catch { @@ -566,9 +566,9 @@ class HostIntegrationCoreApiSetup { let echoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableStringArg = args[0] as? String do { - let args = message as! [Any?] - let aNullableStringArg = args[0] as? String let result = try api.echoNullableString(aNullableString: aNullableStringArg) reply(wrapResult(result)) } catch { @@ -582,9 +582,9 @@ class HostIntegrationCoreApiSetup { let echoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData do { - let args = message as! [Any?] - let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData let result = try api.echoNullableUint8List(aNullableUint8List: aNullableUint8ListArg) reply(wrapResult(result)) } catch { @@ -598,9 +598,9 @@ class HostIntegrationCoreApiSetup { let echoNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableObjectArg = args[0] do { - let args = message as! [Any?] - let aNullableObjectArg = args[0] let result = try api.echoNullableObject(aNullableObject: aNullableObjectArg) reply(wrapResult(result)) } catch { @@ -615,12 +615,8 @@ class HostIntegrationCoreApiSetup { let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopAsyncChannel.setMessageHandler { _, reply in - do { - try api.noopAsync() { - reply(wrapResult(nil)) - } - } catch { - reply(wrapError(error)) + api.noopAsync() { + reply(wrapResult(nil)) } } } else { @@ -630,14 +626,10 @@ class HostIntegrationCoreApiSetup { let echoAsyncStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAsyncStringChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aStringArg = args[0] as! String - try api.echoAsyncString(aString: aStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aStringArg = args[0] as! String + api.echoAsyncString(aString: aStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -646,12 +638,8 @@ class HostIntegrationCoreApiSetup { let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in - do { - try api.callFlutterNoop() { - reply(wrapResult(nil)) - } - } catch { - reply(wrapError(error)) + api.callFlutterNoop() { + reply(wrapResult(nil)) } } } else { @@ -660,14 +648,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoAllTypesChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes - try api.callFlutterEchoAllTypes(everything: everythingArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + api.callFlutterEchoAllTypes(everything: everythingArg) { result in + reply(wrapResult(result)) } } } else { @@ -676,16 +660,12 @@ class HostIntegrationCoreApiSetup { let callFlutterSendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterSendMultipleNullableTypesChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String - try api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -694,14 +674,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoBoolChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool - try api.callFlutterEchoBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + api.callFlutterEchoBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) } } } else { @@ -710,14 +686,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoIntChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 - try api.callFlutterEchoInt(anInt: anIntArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + api.callFlutterEchoInt(anInt: anIntArg) { result in + reply(wrapResult(result)) } } } else { @@ -726,14 +698,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoDoubleChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double - try api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) } } } else { @@ -742,14 +710,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoStringChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aStringArg = args[0] as! String - try api.callFlutterEchoString(aString: aStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aStringArg = args[0] as! String + api.callFlutterEchoString(aString: aStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -758,14 +722,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - try api.callFlutterEchoUint8List(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as! FlutterStandardTypedData + api.callFlutterEchoUint8List(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -774,14 +734,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - try api.callFlutterEchoList(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as! [Any?] + api.callFlutterEchoList(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -790,14 +746,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoMapChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aMapArg = args[0] as! [String?: Any?] - try api.callFlutterEchoMap(aMap: aMapArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aMapArg = args[0] as! [String?: Any?] + api.callFlutterEchoMap(aMap: aMapArg) { result in + reply(wrapResult(result)) } } } else { @@ -806,14 +758,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aBoolArg = args[0] as? Bool - try api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aBoolArg = args[0] as? Bool + api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) } } } else { @@ -822,14 +770,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let anIntArg = args[0] as? Int32 - try api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let anIntArg = args[0] as? Int32 + api.callFlutterEchoNullableInt(anInt: anIntArg) { result in + reply(wrapResult(result)) } } } else { @@ -838,14 +782,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aDoubleArg = args[0] as? Double - try api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aDoubleArg = args[0] as? Double + api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) } } } else { @@ -854,14 +794,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aStringArg = args[0] as? String - try api.callFlutterEchoNullableString(aString: aStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aStringArg = args[0] as? String + api.callFlutterEchoNullableString(aString: aStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -870,14 +806,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as? FlutterStandardTypedData - try api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as? FlutterStandardTypedData + api.callFlutterEchoNullableUint8List(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -886,14 +818,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as? [Any?] - try api.callFlutterEchoNullableList(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as? [Any?] + api.callFlutterEchoNullableList(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -902,14 +830,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aMapArg = args[0] as? [String?: Any?] - try api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aMapArg = args[0] as? [String?: Any?] + api.callFlutterEchoNullableMap(aMap: aMapArg) { result in + reply(wrapResult(result)) } } } else { diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 8c05ef48fae..cc724052894 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -277,26 +277,26 @@ protocol HostIntegrationCoreApi { func echoNullableObject(aNullableObject: Any?) throws -> Any? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping () -> Void) throws + func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) throws - func callFlutterNoop(completion: @escaping () -> Void) throws - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) throws - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) throws - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) throws - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) throws - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) throws - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) throws - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) throws - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) throws - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) throws - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) throws - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) throws - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) throws - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) throws - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) throws - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) throws - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) throws + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) + func callFlutterNoop(completion: @escaping () -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -324,9 +324,9 @@ class HostIntegrationCoreApiSetup { let echoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes do { - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes let result = try api.echoAllTypes(everything: everythingArg) reply(wrapResult(result)) } catch { @@ -340,9 +340,9 @@ class HostIntegrationCoreApiSetup { let echoAllNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAllNullableTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let everythingArg = args[0] as? AllNullableTypes do { - let args = message as! [Any?] - let everythingArg = args[0] as? AllNullableTypes let result = try api.echoAllNullableTypes(everything: everythingArg) reply(wrapResult(result)) } catch { @@ -370,9 +370,9 @@ class HostIntegrationCoreApiSetup { let echoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 do { - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 let result = try api.echoInt(anInt: anIntArg) reply(wrapResult(result)) } catch { @@ -386,9 +386,9 @@ class HostIntegrationCoreApiSetup { let echoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double do { - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double let result = try api.echoDouble(aDouble: aDoubleArg) reply(wrapResult(result)) } catch { @@ -402,9 +402,9 @@ class HostIntegrationCoreApiSetup { let echoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool do { - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool let result = try api.echoBool(aBool: aBoolArg) reply(wrapResult(result)) } catch { @@ -418,9 +418,9 @@ class HostIntegrationCoreApiSetup { let echoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aStringArg = args[0] as! String do { - let args = message as! [Any?] - let aStringArg = args[0] as! String let result = try api.echoString(aString: aStringArg) reply(wrapResult(result)) } catch { @@ -434,9 +434,9 @@ class HostIntegrationCoreApiSetup { let echoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aUint8ListArg = args[0] as! FlutterStandardTypedData do { - let args = message as! [Any?] - let aUint8ListArg = args[0] as! FlutterStandardTypedData let result = try api.echoUint8List(aUint8List: aUint8ListArg) reply(wrapResult(result)) } catch { @@ -450,9 +450,9 @@ class HostIntegrationCoreApiSetup { let echoObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anObjectArg = args[0]! do { - let args = message as! [Any?] - let anObjectArg = args[0]! let result = try api.echoObject(anObject: anObjectArg) reply(wrapResult(result)) } catch { @@ -467,9 +467,9 @@ class HostIntegrationCoreApiSetup { let extractNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { extractNestedNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let wrapperArg = args[0] as! AllNullableTypesWrapper do { - let args = message as! [Any?] - let wrapperArg = args[0] as! AllNullableTypesWrapper let result = try api.extractNestedNullableString(wrapper: wrapperArg) reply(wrapResult(result)) } catch { @@ -484,9 +484,9 @@ class HostIntegrationCoreApiSetup { let createNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.createNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { createNestedNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let nullableStringArg = args[0] as? String do { - let args = message as! [Any?] - let nullableStringArg = args[0] as? String let result = try api.createNestedNullableString(nullableString: nullableStringArg) reply(wrapResult(result)) } catch { @@ -500,11 +500,11 @@ class HostIntegrationCoreApiSetup { let sendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sendMultipleNullableTypesChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String do { - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String let result = try api.sendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) reply(wrapResult(result)) } catch { @@ -518,9 +518,9 @@ class HostIntegrationCoreApiSetup { let echoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableIntChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableIntArg = args[0] as? Int32 do { - let args = message as! [Any?] - let aNullableIntArg = args[0] as? Int32 let result = try api.echoNullableInt(aNullableInt: aNullableIntArg) reply(wrapResult(result)) } catch { @@ -534,9 +534,9 @@ class HostIntegrationCoreApiSetup { let echoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableDoubleChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableDoubleArg = args[0] as? Double do { - let args = message as! [Any?] - let aNullableDoubleArg = args[0] as? Double let result = try api.echoNullableDouble(aNullableDouble: aNullableDoubleArg) reply(wrapResult(result)) } catch { @@ -550,9 +550,9 @@ class HostIntegrationCoreApiSetup { let echoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableBoolChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool do { - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool let result = try api.echoNullableBool(aNullableBool: aNullableBoolArg) reply(wrapResult(result)) } catch { @@ -566,9 +566,9 @@ class HostIntegrationCoreApiSetup { let echoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableStringChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableStringArg = args[0] as? String do { - let args = message as! [Any?] - let aNullableStringArg = args[0] as? String let result = try api.echoNullableString(aNullableString: aNullableStringArg) reply(wrapResult(result)) } catch { @@ -582,9 +582,9 @@ class HostIntegrationCoreApiSetup { let echoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableUint8ListChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData do { - let args = message as! [Any?] - let aNullableUint8ListArg = args[0] as? FlutterStandardTypedData let result = try api.echoNullableUint8List(aNullableUint8List: aNullableUint8ListArg) reply(wrapResult(result)) } catch { @@ -598,9 +598,9 @@ class HostIntegrationCoreApiSetup { let echoNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableObjectArg = args[0] do { - let args = message as! [Any?] - let aNullableObjectArg = args[0] let result = try api.echoNullableObject(aNullableObject: aNullableObjectArg) reply(wrapResult(result)) } catch { @@ -615,12 +615,8 @@ class HostIntegrationCoreApiSetup { let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) if let api = api { noopAsyncChannel.setMessageHandler { _, reply in - do { - try api.noopAsync() { - reply(wrapResult(nil)) - } - } catch { - reply(wrapError(error)) + api.noopAsync() { + reply(wrapResult(nil)) } } } else { @@ -630,14 +626,10 @@ class HostIntegrationCoreApiSetup { let echoAsyncStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { echoAsyncStringChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aStringArg = args[0] as! String - try api.echoAsyncString(aString: aStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aStringArg = args[0] as! String + api.echoAsyncString(aString: aStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -646,12 +638,8 @@ class HostIntegrationCoreApiSetup { let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in - do { - try api.callFlutterNoop() { - reply(wrapResult(nil)) - } - } catch { - reply(wrapError(error)) + api.callFlutterNoop() { + reply(wrapResult(nil)) } } } else { @@ -660,14 +648,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoAllTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoAllTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoAllTypesChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let everythingArg = args[0] as! AllTypes - try api.callFlutterEchoAllTypes(everything: everythingArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let everythingArg = args[0] as! AllTypes + api.callFlutterEchoAllTypes(everything: everythingArg) { result in + reply(wrapResult(result)) } } } else { @@ -676,16 +660,12 @@ class HostIntegrationCoreApiSetup { let callFlutterSendMultipleNullableTypesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterSendMultipleNullableTypesChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aNullableBoolArg = args[0] as? Bool - let aNullableIntArg = args[1] as? Int32 - let aNullableStringArg = args[2] as? String - try api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aNullableBoolArg = args[0] as? Bool + let aNullableIntArg = args[1] as? Int32 + let aNullableStringArg = args[2] as? String + api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -694,14 +674,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoBoolChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aBoolArg = args[0] as! Bool - try api.callFlutterEchoBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aBoolArg = args[0] as! Bool + api.callFlutterEchoBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) } } } else { @@ -710,14 +686,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoIntChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let anIntArg = args[0] as! Int32 - try api.callFlutterEchoInt(anInt: anIntArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let anIntArg = args[0] as! Int32 + api.callFlutterEchoInt(anInt: anIntArg) { result in + reply(wrapResult(result)) } } } else { @@ -726,14 +698,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoDoubleChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aDoubleArg = args[0] as! Double - try api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aDoubleArg = args[0] as! Double + api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) } } } else { @@ -742,14 +710,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoStringChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aStringArg = args[0] as! String - try api.callFlutterEchoString(aString: aStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aStringArg = args[0] as! String + api.callFlutterEchoString(aString: aStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -758,14 +722,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoUint8ListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as! FlutterStandardTypedData - try api.callFlutterEchoUint8List(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as! FlutterStandardTypedData + api.callFlutterEchoUint8List(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -774,14 +734,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as! [Any?] - try api.callFlutterEchoList(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as! [Any?] + api.callFlutterEchoList(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -790,14 +746,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoMapChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aMapArg = args[0] as! [String?: Any?] - try api.callFlutterEchoMap(aMap: aMapArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aMapArg = args[0] as! [String?: Any?] + api.callFlutterEchoMap(aMap: aMapArg) { result in + reply(wrapResult(result)) } } } else { @@ -806,14 +758,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableBool", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableBoolChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aBoolArg = args[0] as? Bool - try api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aBoolArg = args[0] as? Bool + api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in + reply(wrapResult(result)) } } } else { @@ -822,14 +770,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableIntChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableInt", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableIntChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let anIntArg = args[0] as? Int32 - try api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let anIntArg = args[0] as? Int32 + api.callFlutterEchoNullableInt(anInt: anIntArg) { result in + reply(wrapResult(result)) } } } else { @@ -838,14 +782,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableDoubleChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableDoubleChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aDoubleArg = args[0] as? Double - try api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aDoubleArg = args[0] as? Double + api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in + reply(wrapResult(result)) } } } else { @@ -854,14 +794,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableString", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableStringChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aStringArg = args[0] as? String - try api.callFlutterEchoNullableString(aString: aStringArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aStringArg = args[0] as? String + api.callFlutterEchoNullableString(aString: aStringArg) { result in + reply(wrapResult(result)) } } } else { @@ -870,14 +806,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableUint8ListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableUint8ListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as? FlutterStandardTypedData - try api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as? FlutterStandardTypedData + api.callFlutterEchoNullableUint8List(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -886,14 +818,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableListChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableList", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableListChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aListArg = args[0] as? [Any?] - try api.callFlutterEchoNullableList(aList: aListArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aListArg = args[0] as? [Any?] + api.callFlutterEchoNullableList(aList: aListArg) { result in + reply(wrapResult(result)) } } } else { @@ -902,14 +830,10 @@ class HostIntegrationCoreApiSetup { let callFlutterEchoNullableMapChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterEchoNullableMap", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterEchoNullableMapChannel.setMessageHandler { message, reply in - do { - let args = message as! [Any?] - let aMapArg = args[0] as? [String?: Any?] - try api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - reply(wrapResult(result)) - } - } catch { - reply(wrapError(error)) + let args = message as! [Any?] + let aMapArg = args[0] as? [String?: Any?] + api.callFlutterEchoNullableMap(aMap: aMapArg) { result in + reply(wrapResult(result)) } } } else { From a07190cef481f3d767236ea16f383658a8d7fc4d Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 25 Jan 2023 22:41:19 -0800 Subject: [PATCH 09/13] Async error handling --- packages/pigeon/CHANGELOG.md | 4 +- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/swift_generator.dart | 29 +++- .../mock_handler_tester/test/message.dart | 2 +- .../pigeon/mock_handler_tester/test/test.dart | 2 +- .../CoreTests.java | 2 +- .../ios/Classes/CoreTests.gen.h | 2 +- .../ios/Classes/CoreTests.gen.m | 2 +- .../lib/core_tests.gen.dart | 2 +- .../lib/flutter_unittests.gen.dart | 2 +- .../lib/multiple_arity.gen.dart | 2 +- .../lib/non_null_fields.gen.dart | 2 +- .../lib/null_fields.gen.dart | 2 +- .../lib/nullable_returns.gen.dart | 2 +- .../lib/primitive.gen.dart | 2 +- .../lib/src/generated/core_tests.gen.dart | 2 +- .../com/example/test_plugin/CoreTests.gen.kt | 2 +- .../ios/RunnerTests/AsyncHandlersTest.swift | 6 +- .../ios/Classes/CoreTests.gen.swift | 164 ++++++++++++++---- .../test_plugin/ios/Classes/TestPlugin.swift | 132 ++++++++++---- .../macos/Classes/CoreTests.gen.swift | 164 ++++++++++++++---- .../macos/Classes/TestPlugin.swift | 133 ++++++++++---- .../windows/pigeon/core_tests.gen.cpp | 2 +- .../windows/pigeon/core_tests.gen.h | 2 +- packages/pigeon/pubspec.yaml | 2 +- .../pigeon/test/swift_generator_test.dart | 7 +- 26 files changed, 509 insertions(+), 166 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 13085a5a67c..699a6925dab 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,5 +1,7 @@ -## 7.0.5 +## 8.0.0 +* [swift] **BREAKING CHANGE**: Changes async method completion types. +* [swift] Adds error handling to async methods. * [swift] Adds error handling to sync host api methods. ## 7.0.4 diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index ccc7326749b..07277d29036 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -11,7 +11,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '7.0.5'; +const String pigeonVersion = '8.0.0'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 63ec7b74f46..268ee851055 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -394,11 +394,15 @@ import FlutterMacOS final String returnType = method.returnType.isVoid ? '' : _nullsafeSwiftTypeForDartType(method.returnType); + + final String escapeType = + method.returnType.isVoid ? '' : 'Result<$returnType, Error>'; + addDocumentationComments( indent, method.documentationComments, _docCommentSpec); if (method.isAsynchronous) { - argSignature.add('completion: @escaping ($returnType) -> Void'); + argSignature.add('completion: @escaping ($escapeType) -> Void'); indent.writeln('func ${method.name}(${argSignature.join(', ')})'); } else if (method.returnType.isVoid) { indent.writeln( @@ -464,7 +468,17 @@ import FlutterMacOS }); } else { indent.addScoped('{ result in', '}', () { - indent.writeln('reply(wrapResult(result))'); + indent.write('switch result '); + indent.addScoped('{', '}', () { + indent.writeln('case .success(let res):'); + indent.nest(1, () { + indent.writeln('reply(wrapResult(res))'); + }); + indent.writeln('case .failure(let error):'); + indent.nest(1, () { + indent.writeln('reply(wrapError(error))'); + }); + }); }); } } else { @@ -590,8 +604,17 @@ import FlutterMacOS void _writeWrapError(Indent indent) { indent.newln(); - indent.write('private func wrapError(_ error: Error) -> [Any?] '); + indent.write('private func wrapError(_ error: Any) -> [Any?] '); indent.addScoped('{', '}', () { + indent.write('if let flutterError = error as? FlutterError '); + indent.addScoped('{', '}', () { + indent.write('return '); + indent.addScoped('[', ']', () { + indent.writeln('flutterError.code,'); + indent.writeln('flutterError.message,'); + indent.writeln('flutterError.details'); + }); + }); indent.write('return '); indent.addScoped('[', ']', () { indent.writeln(r'"\(error)",'); diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index 9cd02367e12..2de8cd521dd 100644 --- a/packages/pigeon/mock_handler_tester/test/message.dart +++ b/packages/pigeon/mock_handler_tester/test/message.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index 152a0763473..bdd87c30808 100644 --- a/packages/pigeon/mock_handler_tester/test/test.dart +++ b/packages/pigeon/mock_handler_tester/test/test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index 7e4d7ae9964..a484cde5d5b 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.alternate_language_test_plugin; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index b7001f492f1..0a45d33ebd4 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index cae5ac34080..e506e61e278 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "CoreTests.gen.h" diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index 6fb1023d19b..ac5033eec17 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart index 8b416c495ff..e869f1a2a6d 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart index 1d0d98e53b1..4378d4f2f0e 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart index aea9caa9c95..04695f5d9c8 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart index ee30169b714..e53e1119575 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart index 9e2d4b6ddae..9b4749bfb26 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart index 0051028506f..949f79d30fd 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index 6fb1023d19b..ac5033eec17 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index d4eaaef4d47..3c7b113449e 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.test_plugin diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift index a5a4ae7639a..beab8bc6906 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift @@ -7,8 +7,10 @@ import XCTest class MockApi2Host: Api2Host { var output: Int32? - func calculate(value: Value, completion: @escaping (Value) -> Void) { - completion(Value(number: output)) + func calculate(value: Value, completion: @escaping (Result) -> Void) { + let result: Result + result = .success(Value(number: output)) + completion(result) } func voidVoid(completion: @escaping () -> Void) { diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index cc724052894..ace8414eae1 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -20,7 +20,14 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: Error) -> [Any?] { +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } return [ "\(error)", "\(type(of: error))", @@ -279,24 +286,24 @@ protocol HostIntegrationCoreApi { /// test basic asynchronous calling. func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) + func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) func callFlutterNoop(completion: @escaping () -> Void) - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (Result) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) + func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -629,7 +636,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.echoAsyncString(aString: aStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -651,7 +663,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let everythingArg = args[0] as! AllTypes api.callFlutterEchoAllTypes(everything: everythingArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -665,7 +682,12 @@ class HostIntegrationCoreApiSetup { let aNullableIntArg = args[1] as? Int32 let aNullableStringArg = args[2] as? String api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -677,7 +699,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as! Bool api.callFlutterEchoBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -689,7 +716,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as! Int32 api.callFlutterEchoInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -701,7 +733,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as! Double api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -713,7 +750,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.callFlutterEchoString(aString: aStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -725,7 +767,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! FlutterStandardTypedData api.callFlutterEchoUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -737,7 +784,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! [Any?] api.callFlutterEchoList(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -749,7 +801,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as! [String?: Any?] api.callFlutterEchoMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -761,7 +818,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as? Bool api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -773,7 +835,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as? Int32 api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -785,7 +852,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as? Double api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -797,7 +869,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as? String api.callFlutterEchoNullableString(aString: aStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -809,7 +886,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? FlutterStandardTypedData api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -821,7 +903,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? [Any?] api.callFlutterEchoNullableList(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -833,7 +920,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as? [String?: Any?] api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index 14fb5fad285..2523a90d401 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -104,8 +104,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion() } - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) { - completion(aString) + func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) { + let result: Result + result = .success(aString) + completion(result) } func callFlutterNoop(completion: @escaping () -> Void) { @@ -114,79 +116,141 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) { - flutterAPI.echoAllTypes(everything: everything) { completion($0) } + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) { + flutterAPI.echoAllTypes(everything: everything) { + let result: Result + result = .success($0) + completion(result) + } } func callFlutterSendMultipleNullableTypes( aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, - completion: @escaping (AllNullableTypes) -> Void + completion: @escaping (Result) -> Void ) { flutterAPI.sendMultipleNullableTypes( aNullableBool: aNullableBool, aNullableInt: aNullableInt, aNullableString: aNullableString ) { - completion($0) + let result: Result + result = .success($0) + completion(result) } } - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) { - flutterAPI.echoBool(aBool: aBool) { completion($0) } + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) { + flutterAPI.echoBool(aBool: aBool) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) { - flutterAPI.echoInt(anInt: anInt) { completion($0) } + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) { + flutterAPI.echoInt(anInt: anInt) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) { - flutterAPI.echoDouble(aDouble: aDouble) { completion($0) } + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) { + flutterAPI.echoDouble(aDouble: aDouble) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { - flutterAPI.echoString(aString: aString) { completion($0) } + func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) { + flutterAPI.echoString(aString: aString) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { - flutterAPI.echoUint8List(aList: aList) { completion($0) } + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + flutterAPI.echoUint8List(aList: aList) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) { - flutterAPI.echoList(aList: aList) { completion($0) } + func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + flutterAPI.echoList(aList: aList) { + let result: Result<[Any?], Error> + result = .success($0) + completion(result) + } } - func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping ([String? : Any?]) -> Void) { - flutterAPI.echoMap(aMap: aMap) { completion($0) } + func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping (Result<[String? : Any?], Error>) -> Void) { + flutterAPI.echoMap(aMap: aMap) { + let result: Result<[String? : Any?], Error> + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) { - flutterAPI.echoNullableBool(aBool: aBool) { completion($0) } + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableBool(aBool: aBool) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) { - flutterAPI.echoNullableInt(anInt: anInt) { completion($0) } + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableInt(anInt: anInt) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) { - flutterAPI.echoNullableDouble(aDouble: aDouble) { completion($0) } + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableDouble(aDouble: aDouble) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) { - flutterAPI.echoNullableString(aString: aString) { completion($0) } + func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableString(aString: aString) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { - flutterAPI.echoNullableUint8List(aList: aList) { completion($0) } + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableUint8List(aList: aList) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) { - flutterAPI.echoNullableList(aList: aList) { completion($0) } + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { + flutterAPI.echoNullableList(aList: aList) { + let result: Result<[Any?]?, Error> + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping ([String? : Any?]?) -> Void) { - flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } + func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping (Result<[String? : Any?]?, Error>) -> Void) { + flutterAPI.echoNullableMap(aMap: aMap) { + let result: Result<[String? : Any?]?, Error> + result = .success($0) + completion(result) + } } } diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index cc724052894..ace8414eae1 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -20,7 +20,14 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: Error) -> [Any?] { +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } return [ "\(error)", "\(type(of: error))", @@ -279,24 +286,24 @@ protocol HostIntegrationCoreApi { /// test basic asynchronous calling. func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) + func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) func callFlutterNoop(completion: @escaping () -> Void) - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (Result) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) + func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -629,7 +636,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.echoAsyncString(aString: aStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -651,7 +663,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let everythingArg = args[0] as! AllTypes api.callFlutterEchoAllTypes(everything: everythingArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -665,7 +682,12 @@ class HostIntegrationCoreApiSetup { let aNullableIntArg = args[1] as? Int32 let aNullableStringArg = args[2] as? String api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -677,7 +699,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as! Bool api.callFlutterEchoBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -689,7 +716,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as! Int32 api.callFlutterEchoInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -701,7 +733,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as! Double api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -713,7 +750,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.callFlutterEchoString(aString: aStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -725,7 +767,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! FlutterStandardTypedData api.callFlutterEchoUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -737,7 +784,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! [Any?] api.callFlutterEchoList(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -749,7 +801,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as! [String?: Any?] api.callFlutterEchoMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -761,7 +818,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as? Bool api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -773,7 +835,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as? Int32 api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -785,7 +852,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as? Double api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -797,7 +869,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as? String api.callFlutterEchoNullableString(aString: aStringArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -809,7 +886,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? FlutterStandardTypedData api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -821,7 +903,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? [Any?] api.callFlutterEchoNullableList(aList: aListArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { @@ -833,7 +920,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as? [String?: Any?] api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - reply(wrapResult(result)) + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } } } } else { diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index adca55554ad..2abe55b56dd 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -24,6 +24,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { // MARK: HostIntegrationCoreApi implementation func noop() { + } func echoAllTypes(everything: AllTypes) -> AllTypes { @@ -103,8 +104,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion() } - func echoAsyncString(aString: String, completion: @escaping (String) -> Void) { - completion(aString) + func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) { + let result: Result + result = .success(aString) + completion(result) } func callFlutterNoop(completion: @escaping () -> Void) { @@ -113,79 +116,141 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) { - flutterAPI.echoAllTypes(everything: everything) { completion($0) } + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) { + flutterAPI.echoAllTypes(everything: everything) { + let result: Result + result = .success($0) + completion(result) + } } func callFlutterSendMultipleNullableTypes( aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, - completion: @escaping (AllNullableTypes) -> Void + completion: @escaping (Result) -> Void ) { flutterAPI.sendMultipleNullableTypes( aNullableBool: aNullableBool, aNullableInt: aNullableInt, aNullableString: aNullableString ) { - completion($0) + let result: Result + result = .success($0) + completion(result) } } - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) { - flutterAPI.echoBool(aBool: aBool) { completion($0) } + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) { + flutterAPI.echoBool(aBool: aBool) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) { - flutterAPI.echoInt(anInt: anInt) { completion($0) } + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) { + flutterAPI.echoInt(anInt: anInt) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) { - flutterAPI.echoDouble(aDouble: aDouble) { completion($0) } + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) { + flutterAPI.echoDouble(aDouble: aDouble) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { - flutterAPI.echoString(aString: aString) { completion($0) } + func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) { + flutterAPI.echoString(aString: aString) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { - flutterAPI.echoUint8List(aList: aList) { completion($0) } + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + flutterAPI.echoUint8List(aList: aList) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) { - flutterAPI.echoList(aList: aList) { completion($0) } + func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { + flutterAPI.echoList(aList: aList) { + let result: Result<[Any?], Error> + result = .success($0) + completion(result) + } } - func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping ([String? : Any?]) -> Void) { - flutterAPI.echoMap(aMap: aMap) { completion($0) } + func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping (Result<[String? : Any?], Error>) -> Void) { + flutterAPI.echoMap(aMap: aMap) { + let result: Result<[String? : Any?], Error> + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) { - flutterAPI.echoNullableBool(aBool: aBool) { completion($0) } + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableBool(aBool: aBool) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) { - flutterAPI.echoNullableInt(anInt: anInt) { completion($0) } + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableInt(anInt: anInt) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) { - flutterAPI.echoNullableDouble(aDouble: aDouble) { completion($0) } + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableDouble(aDouble: aDouble) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) { - flutterAPI.echoNullableString(aString: aString) { completion($0) } + func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableString(aString: aString) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { - flutterAPI.echoNullableUint8List(aList: aList) { completion($0) } + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { + flutterAPI.echoNullableUint8List(aList: aList) { + let result: Result + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) { - flutterAPI.echoNullableList(aList: aList) { completion($0) } + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { + flutterAPI.echoNullableList(aList: aList) { + let result: Result<[Any?]?, Error> + result = .success($0) + completion(result) + } } - func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping ([String? : Any?]?) -> Void) { - flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } + func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping (Result<[String? : Any?]?, Error>) -> Void) { + flutterAPI.echoNullableMap(aMap: aMap) { + let result: Result<[String? : Any?]?, Error> + result = .success($0) + completion(result) + } } } diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index e1c00cc1002..fbf9638cd68 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index 68a2397261c..c7a58c17f29 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v7.0.5), do not edit directly. +// Autogenerated from Pigeon (v8.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_CORE_TESTS_GEN_H_ diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index b1f09af218b..a812a671bef 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 7.0.5 # This must match the version in lib/generator_tools.dart +version: 8.0.0 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 3cd52d3e1e4..1c2f2132214 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -499,7 +499,7 @@ void main() { final String code = sink.toString(); expect(code, contains('protocol Api')); expect(code, contains('api.doSomething(arg: argArg) { result in')); - expect(code, contains('reply(wrapResult(result))')); + expect(code, contains('reply(wrapResult(res))')); }); test('gen one async Flutter Api', () { @@ -884,7 +884,10 @@ void main() { const SwiftGenerator generator = SwiftGenerator(); generator.generate(swiftOptions, root, sink); final String code = sink.toString(); - expect(code, contains('func doit(completion: @escaping (Int32?) -> Void')); + expect( + code, + contains( + 'func doit(completion: @escaping (Result) -> Void')); }); test('nullable argument host', () { From 5708c41fd239c7f9bb283994b9c7e50c3d3dd723 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Thu, 26 Jan 2023 22:05:14 -0800 Subject: [PATCH 10/13] throwAsyncError all but kotlin + c++ --- packages/pigeon/pigeons/core_tests.dart | 4 +++ .../AlternateLanguageTestPlugin.java | 9 +++++ .../CoreTests.java | 36 +++++++++++++++++++ .../ios/Classes/AlternateLanguageTestPlugin.m | 5 +++ .../ios/Classes/CoreTests.gen.h | 2 ++ .../ios/Classes/CoreTests.gen.m | 20 +++++++++++ .../lib/core_tests.gen.dart | 22 ++++++++++++ .../lib/integration_tests.dart | 8 +++++ .../lib/src/generated/core_tests.gen.dart | 22 ++++++++++++ .../com/example/test_plugin/CoreTests.gen.kt | 20 +++++++++++ .../com/example/test_plugin/TestPlugin.kt | 4 +++ .../ios/Classes/CoreTests.gen.swift | 18 ++++++++++ .../test_plugin/ios/Classes/TestPlugin.swift | 10 ++++-- .../macos/Classes/CoreTests.gen.swift | 18 ++++++++++ .../macos/Classes/TestPlugin.swift | 10 ++++-- .../windows/pigeon/core_tests.gen.cpp | 34 ++++++++++++++++++ .../windows/pigeon/core_tests.gen.h | 4 +++ .../test_plugin/windows/test_plugin.cpp | 7 ++++ .../test_plugin/windows/test_plugin.h | 3 ++ 19 files changed, 252 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 890e7d6e98e..c68d72563db 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -182,6 +182,10 @@ abstract class HostIntegrationCoreApi { @ObjCSelector('echoAsyncString:') String echoAsyncString(String aString); + /// Returns List of error info asynchromously. + @async + Object? throwAsyncError(); + // ========== Flutter API test wrappers ========== @async diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java index 8adeaba6a58..42957f56da0 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java @@ -146,6 +146,15 @@ public void echoAsyncString(@NonNull String aString, Result result) { result.success(aString); } + @Override + public void throwAsyncError(Result result) { + try { + throw new RuntimeException("An error"); + } catch (Exception e) { + result.error(e); + } + } + @Override public void callFlutterNoop(Result result) { flutterApi.noop( diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index a484cde5d5b..e104822d024 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -828,6 +828,8 @@ AllNullableTypes sendMultipleNullableTypes( void noopAsync(Result result); /** Returns the passed string asynchronously. */ void echoAsyncString(@NonNull String aString, Result result); + /** Returns List of error info asynchromously. */ + void throwAsyncError(Result result); void callFlutterNoop(Result result); @@ -1464,6 +1466,40 @@ public void error(Throwable error) { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + Result resultCallback = + new Result() { + public void success(Object result) { + wrapped.add(0, result); + reply.reply(wrapped); + } + + public void error(Throwable error) { + ArrayList wrappedError = wrapError(error); + reply.reply(wrappedError); + } + }; + + api.throwAsyncError(resultCallback); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + reply.reply(wrappedError); + } + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>( diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m index 22cfcc1f18d..3720b3d8a35 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m @@ -132,6 +132,11 @@ - (void)echoAsyncString:(NSString *)aString completion(aString, nil); } +- (void)throwAsyncErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable))completion { + FlutterError *_Nullable error = [FlutterError errorWithCode:@"An error" message:nil details:nil]; + completion(nil, error); +} + - (void)callFlutterNoopWithCompletion:(void (^)(FlutterError *_Nullable))completion { [self.flutterAPI noopWithCompletion:^(NSError *error) { completion(error); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 0a45d33ebd4..433ee0ddc22 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -181,6 +181,8 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// Returns the passed string asynchronously. - (void)echoAsyncString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; +/// Returns List of error info asynchromously. +- (void)throwAsyncErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; - (void)callFlutterNoopWithCompletion:(void (^)(FlutterError *_Nullable))completion; - (void)callFlutterEchoAllTypes:(AllTypes *)everything completion:(void (^)(AllTypes *_Nullable, FlutterError *_Nullable))completion; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index e506e61e278..3fbc953c77f 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -737,6 +737,26 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns List of error info asynchromously. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(throwAsyncErrorWithCompletion:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(throwAsyncErrorWithCompletion:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + [api throwAsyncErrorWithCompletion:^(id _Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop" diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index ac5033eec17..c4009a4d85a 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -788,6 +788,28 @@ class HostIntegrationCoreApi { } } + /// Returns List of error info asynchromously. + Future throwAsyncError() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return replyList[0]; + } + } + Future callFlutterNoop() async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop', codec, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index 78aa5a87e7b..aae78973c9a 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -488,6 +488,14 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final String echoObject = await api.echoAsyncString(sentObject); expect(echoObject, sentObject); }); + + testWidgets('async errors are returned correctly', (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + expect(() async { + await api.throwAsyncError(); + }, throwsA(isA())); + }, skip: targetGenerator == TargetGenerator.kotlin); }); // These tests rely on the ansync Dart->host calls to work correctly, since diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index ac5033eec17..c4009a4d85a 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -788,6 +788,28 @@ class HostIntegrationCoreApi { } } + /// Returns List of error info asynchromously. + Future throwAsyncError() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return replyList[0]; + } + } + Future callFlutterNoop() async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop', codec, diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index 3c7b113449e..0b25e227829 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -269,6 +269,8 @@ interface HostIntegrationCoreApi { fun noopAsync(callback: () -> Unit) /** Returns the passed string asynchronously. */ fun echoAsyncString(aString: String, callback: (String) -> Unit) + /** Returns List of error info asynchromously. */ + fun throwAsyncError(callback: (Any?) -> Unit) fun callFlutterNoop(callback: () -> Unit) fun callFlutterEchoAllTypes(everything: AllTypes, callback: (AllTypes) -> Unit) fun callFlutterSendMultipleNullableTypes(aNullableBool: Boolean?, aNullableInt: Long?, aNullableString: String?, callback: (AllNullableTypes) -> Unit) @@ -675,6 +677,24 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped = listOf() + try { + api.throwAsyncError() { + reply.reply(wrapResult(it)) + } + } catch (exception: Error) { + wrapped = wrapError(exception) + reply.reply(wrapped) + } + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", codec) if (api != null) { diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt index e224d020611..c218d4453ed 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt @@ -112,6 +112,10 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { callback(aString) } + override fun throwAsyncError(callback: (Any?) -> Unit) { + // callback(FlutterError(code: "500", details: "details", message: "message")) + } + override fun callFlutterNoop(callback: () -> Unit) { flutterApi!!.noop() { callback() } } diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index ace8414eae1..049b4dc998f 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -287,6 +287,8 @@ protocol HostIntegrationCoreApi { func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) + /// Returns List of error info asynchromously. + func throwAsyncError(completion: @escaping (Result) -> Void) func callFlutterNoop(completion: @escaping () -> Void) func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (Result) -> Void) @@ -647,6 +649,22 @@ class HostIntegrationCoreApiSetup { } else { echoAsyncStringChannel.setMessageHandler(nil) } + /// Returns List of error info asynchromously. + let throwAsyncErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncErrorChannel.setMessageHandler { _, reply in + api.throwAsyncError() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncErrorChannel.setMessageHandler(nil) + } let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index 2523a90d401..fa2a4170a3b 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -36,7 +36,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw errType.thrownErrow + throw ErrType.thrownErrow } func echoInt(anInt: Int32) -> Int32 { @@ -110,6 +110,12 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(result) } + func throwAsyncError(completion: @escaping (Result) -> Void) { + let result: Result + result = .failure(ErrType.thrownErrow) + completion(result) + } + func callFlutterNoop(completion: @escaping () -> Void) { flutterAPI.noop() { completion() @@ -254,6 +260,6 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } -enum errType: Error { +enum ErrType: Error { case thrownErrow } \ No newline at end of file diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index ace8414eae1..049b4dc998f 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -287,6 +287,8 @@ protocol HostIntegrationCoreApi { func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) + /// Returns List of error info asynchromously. + func throwAsyncError(completion: @escaping (Result) -> Void) func callFlutterNoop(completion: @escaping () -> Void) func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (Result) -> Void) @@ -647,6 +649,22 @@ class HostIntegrationCoreApiSetup { } else { echoAsyncStringChannel.setMessageHandler(nil) } + /// Returns List of error info asynchromously. + let throwAsyncErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + throwAsyncErrorChannel.setMessageHandler { _, reply in + api.throwAsyncError() { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + throwAsyncErrorChannel.setMessageHandler(nil) + } let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 2abe55b56dd..9c8f0219186 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -36,7 +36,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw errType.thrownErrow + throw ErrType.thrownErrow } func echoInt(anInt: Int32) -> Int32 { @@ -110,6 +110,12 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(result) } + func throwAsyncError(completion: @escaping (Result) -> Void) { + let result: Result + result = .failure(ErrType.thrownErrow) + completion(result) + } + func callFlutterNoop(completion: @escaping () -> Void) { flutterAPI.noop() { completion() @@ -254,6 +260,6 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } -enum errType: Error { +enum ErrType: Error { case thrownErrow } \ No newline at end of file diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index fbf9638cd68..b9668a83083 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -1263,6 +1263,40 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const EncodableValue& message, + const flutter::MessageReply& reply) { + try { + api->ThrowAsyncError( + [reply](ErrorOr>&& output) { + if (output.has_error()) { + reply(WrapError(output.error())); + return; + } + EncodableList wrapped; + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back( + EncodableValue(std::move(output_optional).value())); + } else { + wrapped.push_back(EncodableValue()); + } + reply(EncodableValue(std::move(wrapped))); + }); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel->SetMessageHandler(nullptr); + } + } { auto channel = std::make_unique>( binary_messenger, diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index c7a58c17f29..db9cb07c528 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -325,6 +325,10 @@ class HostIntegrationCoreApi { virtual void EchoAsyncString( const std::string& a_string, std::function reply)> result) = 0; + // Returns List of error info asynchromously. + virtual void ThrowAsyncError( + std::function> reply)> + result) = 0; virtual void CallFlutterNoop( std::function reply)> result) = 0; virtual void CallFlutterEchoAllTypes( diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp index 56c0a3a8685..002c0b964dc 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -180,6 +180,13 @@ void TestPlugin::EchoAsyncString( result(a_string); } +void TestPlugin::ThrowAsyncError( + std::function> reply)> + result) { + const FlutterError& error; + result(error) +} + void TestPlugin::CallFlutterNoop( std::function reply)> result) { flutter_api_->Noop([result]() { result(std::nullopt); }, diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h index aa0e19c1852..749d0ea104c 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -78,6 +78,9 @@ class TestPlugin : public flutter::Plugin, const std::string& a_string, std::function reply)> result) override; + void ThrowAsyncError( + std::function> reply)> + result) override; void CallFlutterNoop( std::function< void(std::optional reply)> From 4f784fa11e3a1e8f3c93f4833af8e5482e63bf53 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Fri, 27 Jan 2023 11:09:46 -0800 Subject: [PATCH 11/13] Revert "Async error handling" This reverts commit a07190cef481f3d767236ea16f383658a8d7fc4d. --- packages/pigeon/CHANGELOG.md | 4 +- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/swift_generator.dart | 18 +- .../mock_handler_tester/test/message.dart | 2 +- .../pigeon/mock_handler_tester/test/test.dart | 2 +- packages/pigeon/pigeons/core_tests.dart | 4 - .../AlternateLanguageTestPlugin.java | 9 - .../CoreTests.java | 38 +--- .../ios/Classes/AlternateLanguageTestPlugin.m | 5 - .../ios/Classes/CoreTests.gen.h | 4 +- .../ios/Classes/CoreTests.gen.m | 22 +-- .../lib/core_tests.gen.dart | 24 +-- .../lib/flutter_unittests.gen.dart | 2 +- .../lib/multiple_arity.gen.dart | 2 +- .../lib/non_null_fields.gen.dart | 2 +- .../lib/null_fields.gen.dart | 2 +- .../lib/nullable_returns.gen.dart | 2 +- .../lib/primitive.gen.dart | 2 +- .../lib/integration_tests.dart | 8 - .../lib/src/generated/core_tests.gen.dart | 24 +-- .../com/example/test_plugin/CoreTests.gen.kt | 22 +-- .../com/example/test_plugin/TestPlugin.kt | 4 - .../ios/RunnerTests/AsyncHandlersTest.swift | 6 +- .../ios/Classes/CoreTests.gen.swift | 182 ++++-------------- .../test_plugin/ios/Classes/TestPlugin.swift | 142 ++++---------- .../macos/Classes/CoreTests.gen.swift | 182 ++++-------------- .../macos/Classes/TestPlugin.swift | 143 ++++---------- .../windows/pigeon/core_tests.gen.cpp | 36 +--- .../windows/pigeon/core_tests.gen.h | 6 +- .../test_plugin/windows/test_plugin.cpp | 7 - .../test_plugin/windows/test_plugin.h | 3 - packages/pigeon/pubspec.yaml | 2 +- .../pigeon/test/swift_generator_test.dart | 7 +- 33 files changed, 169 insertions(+), 751 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 699a6925dab..13085a5a67c 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,7 +1,5 @@ -## 8.0.0 +## 7.0.5 -* [swift] **BREAKING CHANGE**: Changes async method completion types. -* [swift] Adds error handling to async methods. * [swift] Adds error handling to sync host api methods. ## 7.0.4 diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 07277d29036..ccc7326749b 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -11,7 +11,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '8.0.0'; +const String pigeonVersion = '7.0.5'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 268ee851055..41ed1c2892f 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -394,15 +394,11 @@ import FlutterMacOS final String returnType = method.returnType.isVoid ? '' : _nullsafeSwiftTypeForDartType(method.returnType); - - final String escapeType = - method.returnType.isVoid ? '' : 'Result<$returnType, Error>'; - addDocumentationComments( indent, method.documentationComments, _docCommentSpec); if (method.isAsynchronous) { - argSignature.add('completion: @escaping ($escapeType) -> Void'); + argSignature.add('completion: @escaping ($returnType) -> Void'); indent.writeln('func ${method.name}(${argSignature.join(', ')})'); } else if (method.returnType.isVoid) { indent.writeln( @@ -468,17 +464,7 @@ import FlutterMacOS }); } else { indent.addScoped('{ result in', '}', () { - indent.write('switch result '); - indent.addScoped('{', '}', () { - indent.writeln('case .success(let res):'); - indent.nest(1, () { - indent.writeln('reply(wrapResult(res))'); - }); - indent.writeln('case .failure(let error):'); - indent.nest(1, () { - indent.writeln('reply(wrapError(error))'); - }); - }); + indent.writeln('reply(wrapResult(result))'); }); } } else { diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index 2de8cd521dd..9cd02367e12 100644 --- a/packages/pigeon/mock_handler_tester/test/message.dart +++ b/packages/pigeon/mock_handler_tester/test/message.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index bdd87c30808..152a0763473 100644 --- a/packages/pigeon/mock_handler_tester/test/test.dart +++ b/packages/pigeon/mock_handler_tester/test/test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index c68d72563db..890e7d6e98e 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -182,10 +182,6 @@ abstract class HostIntegrationCoreApi { @ObjCSelector('echoAsyncString:') String echoAsyncString(String aString); - /// Returns List of error info asynchromously. - @async - Object? throwAsyncError(); - // ========== Flutter API test wrappers ========== @async diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java index 42957f56da0..8adeaba6a58 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java @@ -146,15 +146,6 @@ public void echoAsyncString(@NonNull String aString, Result result) { result.success(aString); } - @Override - public void throwAsyncError(Result result) { - try { - throw new RuntimeException("An error"); - } catch (Exception e) { - result.error(e); - } - } - @Override public void callFlutterNoop(Result result) { flutterApi.noop( diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index e104822d024..7e4d7ae9964 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.alternate_language_test_plugin; @@ -828,8 +828,6 @@ AllNullableTypes sendMultipleNullableTypes( void noopAsync(Result result); /** Returns the passed string asynchronously. */ void echoAsyncString(@NonNull String aString, Result result); - /** Returns List of error info asynchromously. */ - void throwAsyncError(Result result); void callFlutterNoop(Result result); @@ -1466,40 +1464,6 @@ public void error(Throwable error) { channel.setMessageHandler(null); } } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); - try { - Result resultCallback = - new Result() { - public void success(Object result) { - wrapped.add(0, result); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.throwAsyncError(resultCallback); - } catch (Error | RuntimeException exception) { - ArrayList wrappedError = wrapError(exception); - reply.reply(wrappedError); - } - }); - } else { - channel.setMessageHandler(null); - } - } { BasicMessageChannel channel = new BasicMessageChannel<>( diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m index 3720b3d8a35..22cfcc1f18d 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m @@ -132,11 +132,6 @@ - (void)echoAsyncString:(NSString *)aString completion(aString, nil); } -- (void)throwAsyncErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable))completion { - FlutterError *_Nullable error = [FlutterError errorWithCode:@"An error" message:nil details:nil]; - completion(nil, error); -} - - (void)callFlutterNoopWithCompletion:(void (^)(FlutterError *_Nullable))completion { [self.flutterAPI noopWithCompletion:^(NSError *error) { completion(error); diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 433ee0ddc22..b7001f492f1 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @@ -181,8 +181,6 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// Returns the passed string asynchronously. - (void)echoAsyncString:(NSString *)aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion; -/// Returns List of error info asynchromously. -- (void)throwAsyncErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable))completion; - (void)callFlutterNoopWithCompletion:(void (^)(FlutterError *_Nullable))completion; - (void)callFlutterEchoAllTypes:(AllTypes *)everything completion:(void (^)(AllTypes *_Nullable, FlutterError *_Nullable))completion; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index 3fbc953c77f..cae5ac34080 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "CoreTests.gen.h" @@ -737,26 +737,6 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } - /// Returns List of error info asynchromously. - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError" - binaryMessenger:binaryMessenger - codec:HostIntegrationCoreApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(throwAsyncErrorWithCompletion:)], - @"HostIntegrationCoreApi api (%@) doesn't respond to " - @"@selector(throwAsyncErrorWithCompletion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - [api throwAsyncErrorWithCompletion:^(id _Nullable output, FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop" diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index c4009a4d85a..6fb1023d19b 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import @@ -788,28 +788,6 @@ class HostIntegrationCoreApi { } } - /// Returns List of error info asynchromously. - Future throwAsyncError() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return replyList[0]; - } - } - Future callFlutterNoop() async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop', codec, diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart index e869f1a2a6d..8b416c495ff 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart index 4378d4f2f0e..1d0d98e53b1 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart index 04695f5d9c8..aea9caa9c95 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart index e53e1119575..ee30169b714 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart index 9b4749bfb26..9e2d4b6ddae 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart index 949f79d30fd..0051028506f 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index aae78973c9a..78aa5a87e7b 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -488,14 +488,6 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { final String echoObject = await api.echoAsyncString(sentObject); expect(echoObject, sentObject); }); - - testWidgets('async errors are returned correctly', (WidgetTester _) async { - final HostIntegrationCoreApi api = HostIntegrationCoreApi(); - - expect(() async { - await api.throwAsyncError(); - }, throwsA(isA())); - }, skip: targetGenerator == TargetGenerator.kotlin); }); // These tests rely on the ansync Dart->host calls to work correctly, since diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index c4009a4d85a..6fb1023d19b 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import @@ -788,28 +788,6 @@ class HostIntegrationCoreApi { } } - /// Returns List of error info asynchromously. - Future throwAsyncError() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError', codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return replyList[0]; - } - } - Future callFlutterNoop() async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop', codec, diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index 0b25e227829..d4eaaef4d47 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.test_plugin @@ -269,8 +269,6 @@ interface HostIntegrationCoreApi { fun noopAsync(callback: () -> Unit) /** Returns the passed string asynchronously. */ fun echoAsyncString(aString: String, callback: (String) -> Unit) - /** Returns List of error info asynchromously. */ - fun throwAsyncError(callback: (Any?) -> Unit) fun callFlutterNoop(callback: () -> Unit) fun callFlutterEchoAllTypes(everything: AllTypes, callback: (AllTypes) -> Unit) fun callFlutterSendMultipleNullableTypes(aNullableBool: Boolean?, aNullableInt: Long?, aNullableString: String?, callback: (AllNullableTypes) -> Unit) @@ -677,24 +675,6 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } - run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", codec) - if (api != null) { - channel.setMessageHandler { _, reply -> - var wrapped = listOf() - try { - api.throwAsyncError() { - reply.reply(wrapResult(it)) - } - } catch (exception: Error) { - wrapped = wrapError(exception) - reply.reply(wrapped) - } - } - } else { - channel.setMessageHandler(null) - } - } run { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", codec) if (api != null) { diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt index c218d4453ed..e224d020611 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt @@ -112,10 +112,6 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { callback(aString) } - override fun throwAsyncError(callback: (Any?) -> Unit) { - // callback(FlutterError(code: "500", details: "details", message: "message")) - } - override fun callFlutterNoop(callback: () -> Unit) { flutterApi!!.noop() { callback() } } diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift index beab8bc6906..a5a4ae7639a 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift @@ -7,10 +7,8 @@ import XCTest class MockApi2Host: Api2Host { var output: Int32? - func calculate(value: Value, completion: @escaping (Result) -> Void) { - let result: Result - result = .success(Value(number: output)) - completion(result) + func calculate(value: Value, completion: @escaping (Value) -> Void) { + completion(Value(number: output)) } func voidVoid(completion: @escaping () -> Void) { diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 049b4dc998f..cc724052894 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -20,14 +20,7 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: Any) -> [Any?] { - if let flutterError = error as? FlutterError { - return [ - flutterError.code, - flutterError.message, - flutterError.details - ] - } +private func wrapError(_ error: Error) -> [Any?] { return [ "\(error)", "\(type(of: error))", @@ -286,26 +279,24 @@ protocol HostIntegrationCoreApi { /// test basic asynchronous calling. func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) - /// Returns List of error info asynchromously. - func throwAsyncError(completion: @escaping (Result) -> Void) + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) func callFlutterNoop(completion: @escaping () -> Void) - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (Result) -> Void) - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) - func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) - func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -638,33 +629,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.echoAsyncString(aString: aStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { echoAsyncStringChannel.setMessageHandler(nil) } - /// Returns List of error info asynchromously. - let throwAsyncErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", binaryMessenger: binaryMessenger, codec: codec) - if let api = api { - throwAsyncErrorChannel.setMessageHandler { _, reply in - api.throwAsyncError() { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } - } - } - } else { - throwAsyncErrorChannel.setMessageHandler(nil) - } let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in @@ -681,12 +651,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let everythingArg = args[0] as! AllTypes api.callFlutterEchoAllTypes(everything: everythingArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -700,12 +665,7 @@ class HostIntegrationCoreApiSetup { let aNullableIntArg = args[1] as? Int32 let aNullableStringArg = args[2] as? String api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -717,12 +677,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as! Bool api.callFlutterEchoBool(aBool: aBoolArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -734,12 +689,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as! Int32 api.callFlutterEchoInt(anInt: anIntArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -751,12 +701,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as! Double api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -768,12 +713,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.callFlutterEchoString(aString: aStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -785,12 +725,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! FlutterStandardTypedData api.callFlutterEchoUint8List(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -802,12 +737,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! [Any?] api.callFlutterEchoList(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -819,12 +749,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as! [String?: Any?] api.callFlutterEchoMap(aMap: aMapArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -836,12 +761,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as? Bool api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -853,12 +773,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as? Int32 api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -870,12 +785,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as? Double api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -887,12 +797,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as? String api.callFlutterEchoNullableString(aString: aStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -904,12 +809,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? FlutterStandardTypedData api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -921,12 +821,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? [Any?] api.callFlutterEchoNullableList(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -938,12 +833,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as? [String?: Any?] api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index fa2a4170a3b..14fb5fad285 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -36,7 +36,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw ErrType.thrownErrow + throw errType.thrownErrow } func echoInt(anInt: Int32) -> Int32 { @@ -104,16 +104,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion() } - func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) { - let result: Result - result = .success(aString) - completion(result) - } - - func throwAsyncError(completion: @escaping (Result) -> Void) { - let result: Result - result = .failure(ErrType.thrownErrow) - completion(result) + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) { + completion(aString) } func callFlutterNoop(completion: @escaping () -> Void) { @@ -122,144 +114,82 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) { - flutterAPI.echoAllTypes(everything: everything) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) { + flutterAPI.echoAllTypes(everything: everything) { completion($0) } } func callFlutterSendMultipleNullableTypes( aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, - completion: @escaping (Result) -> Void + completion: @escaping (AllNullableTypes) -> Void ) { flutterAPI.sendMultipleNullableTypes( aNullableBool: aNullableBool, aNullableInt: aNullableInt, aNullableString: aNullableString ) { - let result: Result - result = .success($0) - completion(result) + completion($0) } } - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) { - flutterAPI.echoBool(aBool: aBool) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) { + flutterAPI.echoBool(aBool: aBool) { completion($0) } } - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) { - flutterAPI.echoInt(anInt: anInt) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) { + flutterAPI.echoInt(anInt: anInt) { completion($0) } } - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) { - flutterAPI.echoDouble(aDouble: aDouble) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) { + flutterAPI.echoDouble(aDouble: aDouble) { completion($0) } } - func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) { - flutterAPI.echoString(aString: aString) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { + flutterAPI.echoString(aString: aString) { completion($0) } } - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { - flutterAPI.echoUint8List(aList: aList) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { + flutterAPI.echoUint8List(aList: aList) { completion($0) } } - func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - flutterAPI.echoList(aList: aList) { - let result: Result<[Any?], Error> - result = .success($0) - completion(result) - } + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) { + flutterAPI.echoList(aList: aList) { completion($0) } } - func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping (Result<[String? : Any?], Error>) -> Void) { - flutterAPI.echoMap(aMap: aMap) { - let result: Result<[String? : Any?], Error> - result = .success($0) - completion(result) - } + func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping ([String? : Any?]) -> Void) { + flutterAPI.echoMap(aMap: aMap) { completion($0) } } - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableBool(aBool: aBool) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) { + flutterAPI.echoNullableBool(aBool: aBool) { completion($0) } } - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableInt(anInt: anInt) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) { + flutterAPI.echoNullableInt(anInt: anInt) { completion($0) } } - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableDouble(aDouble: aDouble) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) { + flutterAPI.echoNullableDouble(aDouble: aDouble) { completion($0) } } - func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableString(aString: aString) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) { + flutterAPI.echoNullableString(aString: aString) { completion($0) } } - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableUint8List(aList: aList) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { + flutterAPI.echoNullableUint8List(aList: aList) { completion($0) } } - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { - flutterAPI.echoNullableList(aList: aList) { - let result: Result<[Any?]?, Error> - result = .success($0) - completion(result) - } + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) { + flutterAPI.echoNullableList(aList: aList) { completion($0) } } - func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping (Result<[String? : Any?]?, Error>) -> Void) { - flutterAPI.echoNullableMap(aMap: aMap) { - let result: Result<[String? : Any?]?, Error> - result = .success($0) - completion(result) - } + func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping ([String? : Any?]?) -> Void) { + flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } } } -enum ErrType: Error { +enum errType: Error { case thrownErrow } \ No newline at end of file diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 049b4dc998f..cc724052894 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -20,14 +20,7 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: Any) -> [Any?] { - if let flutterError = error as? FlutterError { - return [ - flutterError.code, - flutterError.message, - flutterError.details - ] - } +private func wrapError(_ error: Error) -> [Any?] { return [ "\(error)", "\(type(of: error))", @@ -286,26 +279,24 @@ protocol HostIntegrationCoreApi { /// test basic asynchronous calling. func noopAsync(completion: @escaping () -> Void) /// Returns the passed string asynchronously. - func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) - /// Returns List of error info asynchromously. - func throwAsyncError(completion: @escaping (Result) -> Void) + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) func callFlutterNoop(completion: @escaping () -> Void) - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) - func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (Result) -> Void) - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) - func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) - func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) - func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping (Result<[String?: Any?], Error>) -> Void) - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) - func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, Error>) -> Void) + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) + func callFlutterSendMultipleNullableTypes(aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, completion: @escaping (AllNullableTypes) -> Void) + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) + func callFlutterEchoMap(aMap: [String?: Any?], completion: @escaping ([String?: Any?]) -> Void) + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) + func callFlutterEchoNullableMap(aMap: [String?: Any?]?, completion: @escaping ([String?: Any?]?) -> Void) } /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. @@ -638,33 +629,12 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.echoAsyncString(aString: aStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { echoAsyncStringChannel.setMessageHandler(nil) } - /// Returns List of error info asynchromously. - let throwAsyncErrorChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", binaryMessenger: binaryMessenger, codec: codec) - if let api = api { - throwAsyncErrorChannel.setMessageHandler { _, reply in - api.throwAsyncError() { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } - } - } - } else { - throwAsyncErrorChannel.setMessageHandler(nil) - } let callFlutterNoopChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.callFlutterNoop", binaryMessenger: binaryMessenger, codec: codec) if let api = api { callFlutterNoopChannel.setMessageHandler { _, reply in @@ -681,12 +651,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let everythingArg = args[0] as! AllTypes api.callFlutterEchoAllTypes(everything: everythingArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -700,12 +665,7 @@ class HostIntegrationCoreApiSetup { let aNullableIntArg = args[1] as? Int32 let aNullableStringArg = args[2] as? String api.callFlutterSendMultipleNullableTypes(aNullableBool: aNullableBoolArg, aNullableInt: aNullableIntArg, aNullableString: aNullableStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -717,12 +677,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as! Bool api.callFlutterEchoBool(aBool: aBoolArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -734,12 +689,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as! Int32 api.callFlutterEchoInt(anInt: anIntArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -751,12 +701,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as! Double api.callFlutterEchoDouble(aDouble: aDoubleArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -768,12 +713,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as! String api.callFlutterEchoString(aString: aStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -785,12 +725,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! FlutterStandardTypedData api.callFlutterEchoUint8List(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -802,12 +737,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as! [Any?] api.callFlutterEchoList(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -819,12 +749,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as! [String?: Any?] api.callFlutterEchoMap(aMap: aMapArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -836,12 +761,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aBoolArg = args[0] as? Bool api.callFlutterEchoNullableBool(aBool: aBoolArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -853,12 +773,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let anIntArg = args[0] as? Int32 api.callFlutterEchoNullableInt(anInt: anIntArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -870,12 +785,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aDoubleArg = args[0] as? Double api.callFlutterEchoNullableDouble(aDouble: aDoubleArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -887,12 +797,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aStringArg = args[0] as? String api.callFlutterEchoNullableString(aString: aStringArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -904,12 +809,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? FlutterStandardTypedData api.callFlutterEchoNullableUint8List(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -921,12 +821,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aListArg = args[0] as? [Any?] api.callFlutterEchoNullableList(aList: aListArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { @@ -938,12 +833,7 @@ class HostIntegrationCoreApiSetup { let args = message as! [Any?] let aMapArg = args[0] as? [String?: Any?] api.callFlutterEchoNullableMap(aMap: aMapArg) { result in - switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) - } + reply(wrapResult(result)) } } } else { diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 9c8f0219186..adca55554ad 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -24,7 +24,6 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { // MARK: HostIntegrationCoreApi implementation func noop() { - } func echoAllTypes(everything: AllTypes) -> AllTypes { @@ -36,7 +35,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw ErrType.thrownErrow + throw errType.thrownErrow } func echoInt(anInt: Int32) -> Int32 { @@ -104,16 +103,8 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion() } - func echoAsyncString(aString: String, completion: @escaping (Result) -> Void) { - let result: Result - result = .success(aString) - completion(result) - } - - func throwAsyncError(completion: @escaping (Result) -> Void) { - let result: Result - result = .failure(ErrType.thrownErrow) - completion(result) + func echoAsyncString(aString: String, completion: @escaping (String) -> Void) { + completion(aString) } func callFlutterNoop(completion: @escaping () -> Void) { @@ -122,144 +113,82 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } - func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (Result) -> Void) { - flutterAPI.echoAllTypes(everything: everything) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoAllTypes(everything: AllTypes, completion: @escaping (AllTypes) -> Void) { + flutterAPI.echoAllTypes(everything: everything) { completion($0) } } func callFlutterSendMultipleNullableTypes( aNullableBool: Bool?, aNullableInt: Int32?, aNullableString: String?, - completion: @escaping (Result) -> Void + completion: @escaping (AllNullableTypes) -> Void ) { flutterAPI.sendMultipleNullableTypes( aNullableBool: aNullableBool, aNullableInt: aNullableInt, aNullableString: aNullableString ) { - let result: Result - result = .success($0) - completion(result) + completion($0) } } - func callFlutterEchoBool(aBool: Bool, completion: @escaping (Result) -> Void) { - flutterAPI.echoBool(aBool: aBool) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoBool(aBool: Bool, completion: @escaping (Bool) -> Void) { + flutterAPI.echoBool(aBool: aBool) { completion($0) } } - func callFlutterEchoInt(anInt: Int32, completion: @escaping (Result) -> Void) { - flutterAPI.echoInt(anInt: anInt) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoInt(anInt: Int32, completion: @escaping (Int32) -> Void) { + flutterAPI.echoInt(anInt: anInt) { completion($0) } } - func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Result) -> Void) { - flutterAPI.echoDouble(aDouble: aDouble) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoDouble(aDouble: Double, completion: @escaping (Double) -> Void) { + flutterAPI.echoDouble(aDouble: aDouble) { completion($0) } } - func callFlutterEchoString(aString: String, completion: @escaping (Result) -> Void) { - flutterAPI.echoString(aString: aString) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoString(aString: String, completion: @escaping (String) -> Void) { + flutterAPI.echoString(aString: aString) { completion($0) } } - func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { - flutterAPI.echoUint8List(aList: aList) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoUint8List(aList: FlutterStandardTypedData, completion: @escaping (FlutterStandardTypedData) -> Void) { + flutterAPI.echoUint8List(aList: aList) { completion($0) } } - func callFlutterEchoList(aList: [Any?], completion: @escaping (Result<[Any?], Error>) -> Void) { - flutterAPI.echoList(aList: aList) { - let result: Result<[Any?], Error> - result = .success($0) - completion(result) - } + func callFlutterEchoList(aList: [Any?], completion: @escaping ([Any?]) -> Void) { + flutterAPI.echoList(aList: aList) { completion($0) } } - func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping (Result<[String? : Any?], Error>) -> Void) { - flutterAPI.echoMap(aMap: aMap) { - let result: Result<[String? : Any?], Error> - result = .success($0) - completion(result) - } + func callFlutterEchoMap(aMap: [String? : Any?], completion: @escaping ([String? : Any?]) -> Void) { + flutterAPI.echoMap(aMap: aMap) { completion($0) } } - func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableBool(aBool: aBool) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableBool(aBool: Bool?, completion: @escaping (Bool?) -> Void) { + flutterAPI.echoNullableBool(aBool: aBool) { completion($0) } } - func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableInt(anInt: anInt) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableInt(anInt: Int32?, completion: @escaping (Int32?) -> Void) { + flutterAPI.echoNullableInt(anInt: anInt) { completion($0) } } - func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableDouble(aDouble: aDouble) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableDouble(aDouble: Double?, completion: @escaping (Double?) -> Void) { + flutterAPI.echoNullableDouble(aDouble: aDouble) { completion($0) } } - func callFlutterEchoNullableString(aString: String?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableString(aString: aString) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableString(aString: String?, completion: @escaping (String?) -> Void) { + flutterAPI.echoNullableString(aString: aString) { completion($0) } } - func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { - flutterAPI.echoNullableUint8List(aList: aList) { - let result: Result - result = .success($0) - completion(result) - } + func callFlutterEchoNullableUint8List(aList: FlutterStandardTypedData?, completion: @escaping (FlutterStandardTypedData?) -> Void) { + flutterAPI.echoNullableUint8List(aList: aList) { completion($0) } } - func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping (Result<[Any?]?, Error>) -> Void) { - flutterAPI.echoNullableList(aList: aList) { - let result: Result<[Any?]?, Error> - result = .success($0) - completion(result) - } + func callFlutterEchoNullableList(aList: [Any?]?, completion: @escaping ([Any?]?) -> Void) { + flutterAPI.echoNullableList(aList: aList) { completion($0) } } - func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping (Result<[String? : Any?]?, Error>) -> Void) { - flutterAPI.echoNullableMap(aMap: aMap) { - let result: Result<[String? : Any?]?, Error> - result = .success($0) - completion(result) - } + func callFlutterEchoNullableMap(aMap: [String? : Any?]?, completion: @escaping ([String? : Any?]?) -> Void) { + flutterAPI.echoNullableMap(aMap: aMap) { completion($0) } } } -enum ErrType: Error { +enum errType: Error { case thrownErrow } \ No newline at end of file diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index b9668a83083..e1c00cc1002 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS @@ -1263,40 +1263,6 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } - { - auto channel = std::make_unique>( - binary_messenger, - "dev.flutter.pigeon.HostIntegrationCoreApi.throwAsyncError", - &GetCodec()); - if (api != nullptr) { - channel->SetMessageHandler( - [api](const EncodableValue& message, - const flutter::MessageReply& reply) { - try { - api->ThrowAsyncError( - [reply](ErrorOr>&& output) { - if (output.has_error()) { - reply(WrapError(output.error())); - return; - } - EncodableList wrapped; - auto output_optional = std::move(output).TakeValue(); - if (output_optional) { - wrapped.push_back( - EncodableValue(std::move(output_optional).value())); - } else { - wrapped.push_back(EncodableValue()); - } - reply(EncodableValue(std::move(wrapped))); - }); - } catch (const std::exception& exception) { - reply(WrapError(exception.what())); - } - }); - } else { - channel->SetMessageHandler(nullptr); - } - } { auto channel = std::make_unique>( binary_messenger, diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index db9cb07c528..68a2397261c 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v8.0.0), do not edit directly. +// Autogenerated from Pigeon (v7.0.5), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_CORE_TESTS_GEN_H_ @@ -325,10 +325,6 @@ class HostIntegrationCoreApi { virtual void EchoAsyncString( const std::string& a_string, std::function reply)> result) = 0; - // Returns List of error info asynchromously. - virtual void ThrowAsyncError( - std::function> reply)> - result) = 0; virtual void CallFlutterNoop( std::function reply)> result) = 0; virtual void CallFlutterEchoAllTypes( diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp index 002c0b964dc..56c0a3a8685 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -180,13 +180,6 @@ void TestPlugin::EchoAsyncString( result(a_string); } -void TestPlugin::ThrowAsyncError( - std::function> reply)> - result) { - const FlutterError& error; - result(error) -} - void TestPlugin::CallFlutterNoop( std::function reply)> result) { flutter_api_->Noop([result]() { result(std::nullopt); }, diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h index 749d0ea104c..aa0e19c1852 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -78,9 +78,6 @@ class TestPlugin : public flutter::Plugin, const std::string& a_string, std::function reply)> result) override; - void ThrowAsyncError( - std::function> reply)> - result) override; void CallFlutterNoop( std::function< void(std::optional reply)> diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index a812a671bef..b1f09af218b 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 8.0.0 # This must match the version in lib/generator_tools.dart +version: 7.0.5 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 1c2f2132214..3cd52d3e1e4 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -499,7 +499,7 @@ void main() { final String code = sink.toString(); expect(code, contains('protocol Api')); expect(code, contains('api.doSomething(arg: argArg) { result in')); - expect(code, contains('reply(wrapResult(res))')); + expect(code, contains('reply(wrapResult(result))')); }); test('gen one async Flutter Api', () { @@ -884,10 +884,7 @@ void main() { const SwiftGenerator generator = SwiftGenerator(); generator.generate(swiftOptions, root, sink); final String code = sink.toString(); - expect( - code, - contains( - 'func doit(completion: @escaping (Result) -> Void')); + expect(code, contains('func doit(completion: @escaping (Int32?) -> Void')); }); test('nullable argument host', () { From 3312f9915f597ac0c7685479ac7727e4eb1ff35a Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Fri, 27 Jan 2023 11:11:43 -0800 Subject: [PATCH 12/13] gen --- .../test_plugin/ios/Classes/CoreTests.gen.swift | 9 ++++++++- .../test_plugin/macos/Classes/CoreTests.gen.swift | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index cc724052894..70126026f48 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -20,7 +20,14 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: Error) -> [Any?] { +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } return [ "\(error)", "\(type(of: error))", diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index cc724052894..70126026f48 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -20,7 +20,14 @@ private func wrapResult(_ result: Any?) -> [Any?] { return [result] } -private func wrapError(_ error: Error) -> [Any?] { +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } return [ "\(error)", "\(type(of: error))", From e73cab226ebd5104adcd223eccca02d3e1aa749a Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Fri, 27 Jan 2023 12:39:20 -0800 Subject: [PATCH 13/13] nit --- .../platform_tests/test_plugin/ios/Classes/TestPlugin.swift | 4 ++-- .../platform_tests/test_plugin/macos/Classes/TestPlugin.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index 73405810cce..cd3a07f2dec 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -36,7 +36,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw errType.thrownErrow + throw ErrType.thrownErrow } func echo(_ anInt: Int32) -> Int32 { @@ -190,6 +190,6 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } -enum errType: Error { +enum ErrType: Error { case thrownErrow } \ No newline at end of file diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 63a8b106715..c9c11446d76 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -35,7 +35,7 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } func throwError() throws { - throw errType.thrownErrow + throw ErrType.thrownErrow } func echo(_ anInt: Int32) -> Int32 { @@ -189,6 +189,6 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { } } -enum errType: Error { +enum ErrType: Error { case thrownErrow } \ No newline at end of file