diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index bac4e049fba4..d5f23a5a9263 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,12 @@ +## 13.1.0 + +* [swift] Fixes Flutter Api void return error handling. + * This shouldn't be breaking for anyone, but if you were incorrectly getting + success responses, you may now be failing (correctly). +* Adds method channel name to error response when channel fails to connect. +* Reduces code generation duplication. +* Changes some methods to only be generated if needed. + ## 13.0.0 * **Breaking Change** [objc] Eliminates boxing of non-nullable primitive types diff --git a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java index ac3186ee573f..319780d7b71f 100644 --- a/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java +++ b/packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java @@ -55,6 +55,12 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { return errorList; } + @NonNull + protected static FlutterError createConnectionError(@NonNull String channelName) { + return new FlutterError( + "channel-error", "Unable to establish connection on channel: " + channelName + ".", ""); + } + public enum Code { ONE(0), TWO(1); @@ -341,11 +347,10 @@ public MessageFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { } public void flutterMethod(@Nullable String aStringArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aStringArg)), channelReply -> { @@ -369,9 +374,7 @@ public void flutterMethod(@Nullable String aStringArg, @NonNull Result r result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } diff --git a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt index 4fb36eedd175..96104475a589 100644 --- a/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt +++ b/packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt @@ -33,6 +33,9 @@ private fun wrapError(exception: Throwable): List { } } +private fun createConnectionError(channelName: String): FlutterError { + return FlutterError("channel-error", "Unable to establish connection on channel: '$channelName'.", "")} + /** * Error class for passing custom error details to Flutter via a thrown PlatformException. * @property code The error code. @@ -189,7 +192,8 @@ class MessageFlutterApi(private val binaryMessenger: BinaryMessenger) { } } fun flutterMethod(aStringArg: String?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod", codec) + val channelName = "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { @@ -201,7 +205,7 @@ class MessageFlutterApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } diff --git a/packages/pigeon/example/app/ios/Runner/Messages.g.swift b/packages/pigeon/example/app/ios/Runner/Messages.g.swift index ef38ee5849ca..ad6a337a6db3 100644 --- a/packages/pigeon/example/app/ios/Runner/Messages.g.swift +++ b/packages/pigeon/example/app/ios/Runner/Messages.g.swift @@ -13,10 +13,6 @@ import FlutterMacOS #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil -} - private func wrapResult(_ result: Any?) -> [Any?] { return [result] } @@ -36,6 +32,14 @@ private func wrapError(_ error: Any) -> [Any?] { ] } +private func createConnectionError(withChannelName channelName: String) -> FlutterError { + return FlutterError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? @@ -175,18 +179,19 @@ class ExampleHostApiSetup { } /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. protocol MessageFlutterApiProtocol { - func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) + func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) } class MessageFlutterApi: MessageFlutterApiProtocol { private let binaryMessenger: FlutterBinaryMessenger init(binaryMessenger: FlutterBinaryMessenger){ self.binaryMessenger = binaryMessenger } - func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod", binaryMessenger: binaryMessenger) + func flutterMethod(aString aStringArg: String?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { diff --git a/packages/pigeon/example/app/lib/src/messages.g.dart b/packages/pigeon/example/app/lib/src/messages.g.dart index 52d40138f0fa..a07585d8bd0c 100644 --- a/packages/pigeon/example/app/lib/src/messages.g.dart +++ b/packages/pigeon/example/app/lib/src/messages.g.dart @@ -11,6 +11,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -97,16 +104,16 @@ class ExampleHostApi { static const MessageCodec codec = _ExampleHostApiCodec(); Future getHostLanguage() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -124,16 +131,17 @@ class ExampleHostApi { } Future add(int arg_a, int arg_b) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_a, arg_b]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -151,17 +159,17 @@ class ExampleHostApi { } Future sendMessage(MessageData arg_message) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_message]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/example/app/macos/Runner/messages.g.m b/packages/pigeon/example/app/macos/Runner/messages.g.m index 6861a6b7d6fa..90983b10cd22 100644 --- a/packages/pigeon/example/app/macos/Runner/messages.g.m +++ b/packages/pigeon/example/app/macos/Runner/messages.g.m @@ -16,16 +16,6 @@ #error File requires ARC to be enabled. #endif -@implementation PGNCodeBox -- (instancetype)initWithValue:(PGNCode)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - static NSArray *wrapResult(id result, FlutterError *error) { if (error) { return @[ @@ -34,11 +24,31 @@ - (instancetype)initWithValue:(PGNCode)value { } return @[ result ?: [NSNull null] ]; } + +static FlutterError *createConnectionError(NSString *channelName) { + return [FlutterError + errorWithCode:@"channel-error" + message:[NSString stringWithFormat:@"%@/%@/%@", + @"Unable to establish connection on channel: '", + channelName, @"'."] + details:@""]; +} + static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } +@implementation PGNCodeBox +- (instancetype)initWithValue:(PGNCode)value { + self = [super init]; + if (self) { + _value = value; + } + return self; +} +@end + @interface PGNMessageData () + (PGNMessageData *)fromList:(NSArray *)list; + (nullable PGNMessageData *)nullableFromList:(NSArray *)list; @@ -213,11 +223,12 @@ - (instancetype)initWithBinaryMessenger:(NSObject *)bina } - (void)flutterMethodAString:(nullable NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod" - binaryMessenger:self.binaryMessenger - codec:PGNMessageFlutterApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:PGNMessageFlutterApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -230,10 +241,7 @@ - (void)flutterMethodAString:(nullable NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } diff --git a/packages/pigeon/example/app/windows/runner/messages.g.cpp b/packages/pigeon/example/app/windows/runner/messages.g.cpp index 3e065a5a9b71..4541b9d4f369 100644 --- a/packages/pigeon/example/app/windows/runner/messages.g.cpp +++ b/packages/pigeon/example/app/windows/runner/messages.g.cpp @@ -24,6 +24,13 @@ using flutter::EncodableList; using flutter::EncodableMap; using flutter::EncodableValue; +FlutterError CreateConnectionError(const std::string channel_name) { + return FlutterError( + "channel-error", + "Unable to establish connection on channel: '" + channel_name + "'.", + EncodableValue("")); +} + // MessageData MessageData::MessageData(const Code& code, const EncodableMap& data) @@ -263,39 +270,38 @@ void MessageFlutterApi::FlutterMethod( const std::string* a_string_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi." - "flutterMethod", - &GetCodec()); + "flutterMethod"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_string_arg ? EncodableValue(*a_string_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = - std::get(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = + std::get(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } } // namespace pigeon_example diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 4853e3b963f6..fb52a13aa83f 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -191,7 +191,17 @@ class CppHeaderGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - _writeErrorOr(indent, friends: root.apis.map((Api api) => api.name)); + final bool hasHostApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.host); + final bool hasFlutterApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.flutter); + + if (hasHostApi) { + _writeErrorOr(indent, friends: root.apis.map((Api api) => api.name)); + } + if (hasFlutterApi) { + // Nothing yet. + } } @override @@ -638,6 +648,15 @@ class CppSourceGenerator extends StructuredGenerator { indent.writeln('using $using;'); } indent.newln(); + _writeFunctionDefinition(indent, 'CreateConnectionError', + returnType: 'FlutterError', + parameters: ['const std::string channel_name'], body: () { + indent.format(''' + return FlutterError( + "channel-error", + "Unable to establish connection on channel: '" + channel_name + "'.", + EncodableValue(""));'''); + }); } @override @@ -831,7 +850,6 @@ class CppSourceGenerator extends StructuredGenerator { 'return flutter::StandardMessageCodec::GetInstance(&$codeSerializerName::GetInstance());'); }); for (final Method func in api.methods) { - final String channelName = makeChannelName(api, func, dartPackageName); final HostDatatype returnType = getHostDatatype(func.returnType, root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType); @@ -853,9 +871,11 @@ class CppSourceGenerator extends StructuredGenerator { returnType: _voidType, parameters: parameters, body: () { const String channel = 'channel'; + indent.writeln( + 'const std::string channel_name = "${makeChannelName(api, func, dartPackageName)}";'); indent.writeln( 'auto channel = std::make_unique>(binary_messenger_, ' - '"$channelName", &GetCodec());'); + 'channel_name, &GetCodec());'); // Convert arguments to EncodableValue versions. const String argumentListVariableName = 'encoded_api_arguments'; @@ -875,7 +895,7 @@ class CppSourceGenerator extends StructuredGenerator { indent.write('$channel->Send($argumentListVariableName, ' // ignore: missing_whitespace_between_adjacent_strings - '[on_success = std::move(on_success), on_error = std::move(on_error)]' + '[channel_name, on_success = std::move(on_success), on_error = std::move(on_error)]' '(const uint8_t* reply, size_t reply_size) '); indent.addScoped('{', '});', () { String successCallbackArgument; @@ -890,7 +910,7 @@ class CppSourceGenerator extends StructuredGenerator { indent.writeScoped('if ($listReplyName) {', '} ', () { indent.writeScoped('if ($listReplyName->size() > 1) {', '} ', () { indent.writeln( - 'on_error(FlutterError( std::get($listReplyName->at(0)), std::get($listReplyName->at(1)), $listReplyName->at(2)));'); + 'on_error(FlutterError(std::get($listReplyName->at(0)), std::get($listReplyName->at(1)), $listReplyName->at(2)));'); }, addTrailingNewline: false); indent.addScoped('else {', '}', () { if (func.returnType.isVoid) { @@ -909,8 +929,7 @@ class CppSourceGenerator extends StructuredGenerator { }); }, addTrailingNewline: false); indent.addScoped('else {', '} ', () { - indent.writeln( - 'on_error(FlutterError("channel-error", "Unable to establish connection on channel.", EncodableValue("")));'); + indent.writeln('on_error(CreateConnectionError(channel_name));'); }); }); }); diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index cff3a7b0fd21..672cab1c0709 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -550,13 +550,14 @@ final BinaryMessenger? _binaryMessenger; 'Future<${_addGenericTypesNullable(func.returnType)}> ${func.name}($argSignature) async ', ); indent.addScoped('{', '}', () { - final String channelName = - makeChannelName(api, func, dartPackageName); indent.writeln( - 'final BasicMessageChannel channel = BasicMessageChannel('); - indent.nest(2, () { - indent.writeln("'$channelName', codec,"); - indent.writeln('binaryMessenger: _binaryMessenger);'); + "const String channelName = '${makeChannelName(api, func, dartPackageName)}';"); + indent.writeScoped( + 'final BasicMessageChannel channel = BasicMessageChannel(', + ');', () { + indent.writeln('channelName,'); + indent.writeln('codec,'); + indent.writeln('binaryMessenger: _binaryMessenger,'); }); final String returnType = _makeGenericTypeArguments(func.returnType); final String genericCastCall = _makeGenericCastCall(func.returnType); @@ -586,10 +587,7 @@ final BinaryMessenger? _binaryMessenger; final List? replyList = \t\tawait channel.send($sendArgument) as List?; if (replyList == null) { -\tthrow PlatformException( -\t\tcode: 'channel-error', -\t\tmessage: 'Unable to establish connection on channel.', -\t); +\tthrow _createConnectionError(channelName); } else if (replyList.length > 1) { \tthrow PlatformException( \t\tcode: replyList[0]! as String, @@ -705,11 +703,22 @@ if (replyList == null) { Indent indent, { required String dartPackageName, }) { - _writeWrapResponse(generatorOptions, root, indent); + final bool hasHostApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.host); + final bool hasFlutterApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.flutter); + + if (hasHostApi) { + _writeCreateConnectionError(indent); + } + if (hasFlutterApi) { + _writeWrapResponse(generatorOptions, root, indent); + } } /// Writes [wrapResponse] method. void _writeWrapResponse(DartOptions opt, Root root, Indent indent) { + indent.newln(); indent.writeScoped( 'List wrapResponse({Object? result, PlatformException? error, bool empty = false}) {', '}', () { @@ -723,6 +732,17 @@ if (replyList == null) { 'return [error.code, error.message, error.details];'); }); } + + void _writeCreateConnectionError(Indent indent) { + indent.newln(); + indent.format(''' +PlatformException _createConnectionError(String channelName) { +\treturn PlatformException( +\t\tcode: 'channel-error', +\t\tmessage: 'Unable to establish connection on channel: "\$channelName".', +\t); +}'''); + } } String _escapeForDartSingleQuotedString(String raw) { diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index e0120ab316c0..f0388e785158 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -13,7 +13,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '13.0.0'; +const String pigeonVersion = '13.1.0'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/java_generator.dart b/packages/pigeon/lib/java_generator.dart index 6569e84bba4b..ca1e3b5bd1ac 100644 --- a/packages/pigeon/lib/java_generator.dart +++ b/packages/pigeon/lib/java_generator.dart @@ -456,7 +456,6 @@ class JavaGenerator extends StructuredGenerator { for (final Method func in api.methods) { final String resultType = func.returnType.isNullable ? 'NullableResult' : 'Result'; - final String channelName = makeChannelName(api, func, dartPackageName); final String returnType = func.returnType.isVoid ? 'Void' : _javaTypeForDartType(func.returnType); @@ -489,11 +488,13 @@ class JavaGenerator extends StructuredGenerator { } indent.addScoped('{', '}', () { const String channel = 'channel'; + indent.writeln( + 'final String channelName = "${makeChannelName(api, func, dartPackageName)}";'); indent.writeln('BasicMessageChannel $channel ='); indent.nest(2, () { indent.writeln('new BasicMessageChannel<>('); indent.nest(2, () { - indent.writeln('binaryMessenger, "$channelName", getCodec());'); + indent.writeln('binaryMessenger, channelName, getCodec());'); }); }); indent.writeln('$channel.send('); @@ -545,7 +546,7 @@ class JavaGenerator extends StructuredGenerator { }, addTrailingNewline: false); indent.addScoped(' else {', '} ', () { indent.writeln( - 'result.error(new FlutterError("channel-error", "Unable to establish connection on channel.", ""));'); + 'result.error(createConnectionError(channelName));'); }); }); }); @@ -945,6 +946,16 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { }'''); } + void _writeCreateConnectionError(Indent indent) { + indent.writeln('@NonNull'); + indent.writeScoped( + 'protected static FlutterError createConnectionError(@NonNull String channelName) {', + '}', () { + indent.writeln( + 'return new FlutterError("channel-error", "Unable to establish connection on channel: " + channelName + ".", "");'); + }); + } + @override void writeGeneralUtilities( JavaOptions generatorOptions, @@ -952,10 +963,21 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { Indent indent, { required String dartPackageName, }) { + final bool hasHostApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.host); + final bool hasFlutterApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.flutter); + indent.newln(); _writeErrorClass(indent); - indent.newln(); - _writeWrapError(indent); + if (hasHostApi) { + indent.newln(); + _writeWrapError(indent); + } + if (hasFlutterApi) { + indent.newln(); + _writeCreateConnectionError(indent); + } } @override diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index 8370927631ef..9e7c1327435e 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -375,7 +375,6 @@ class KotlinGenerator extends StructuredGenerator { }); for (final Method func in api.methods) { - final String channelName = makeChannelName(api, func, dartPackageName); final String returnType = func.returnType.isVoid ? 'Unit' : _nullsafeKotlinTypeForDartType(func.returnType); @@ -406,7 +405,9 @@ class KotlinGenerator extends StructuredGenerator { indent.addScoped('{', '}', () { const String channel = 'channel'; indent.writeln( - 'val $channel = BasicMessageChannel(binaryMessenger, "$channelName", codec)'); + 'val channelName = "${makeChannelName(api, func, dartPackageName)}"'); + indent.writeln( + 'val $channel = BasicMessageChannel(binaryMessenger, channelName, codec)'); indent.writeScoped('$channel.send($sendArgument) {', '}', () { indent.writeScoped('if (it is List<*>) {', '} ', () { indent.writeScoped('if (it.size > 1) {', '} ', () { @@ -441,7 +442,7 @@ class KotlinGenerator extends StructuredGenerator { }, addTrailingNewline: false); indent.addScoped('else {', '} ', () { indent.writeln( - 'callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", "")));'); + 'callback(Result.failure(createConnectionError(channelName)));'); }); }); }); @@ -738,6 +739,16 @@ class KotlinGenerator extends StructuredGenerator { indent.addln(' : Throwable()'); } + void _writeCreateConnectionError(Indent indent) { + indent.newln(); + indent.write( + 'private fun createConnectionError(channelName: String): FlutterError '); + indent.addScoped('{', '}', () { + indent.write( + 'return FlutterError("channel-error", "Unable to establish connection on channel: \'\$channelName\'.", "")'); + }); + } + @override void writeGeneralUtilities( KotlinOptions generatorOptions, @@ -745,8 +756,18 @@ class KotlinGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - _writeWrapResult(indent); - _writeWrapError(generatorOptions, indent); + final bool hasHostApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.host); + final bool hasFlutterApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.flutter); + + if (hasHostApi) { + _writeWrapResult(indent); + _writeWrapError(generatorOptions, indent); + } + if (hasFlutterApi) { + _writeCreateConnectionError(indent); + } _writeErrorClass(generatorOptions, indent); } } diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index ccae81868675..96c02bf26dd3 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -476,6 +476,7 @@ class ObjcSourceGenerator extends StructuredGenerator { }) { final String enumName = _enumName(anEnum.name, prefix: generatorOptions.prefix); + indent.newln(); addDocumentationComments( indent, anEnum.documentationComments, _docCommentSpec); indent.writeln( @@ -490,7 +491,6 @@ class ObjcSourceGenerator extends StructuredGenerator { indent.writeln('return self;'); }); indent.writeln('@end'); - indent.newln(); } @override @@ -500,10 +500,6 @@ class ObjcSourceGenerator extends StructuredGenerator { Indent indent, { required String dartPackageName, }) { - _writeObjcSourceHelperFunctions(indent, - hasHostApiMethods: root.apis.any((Api api) => - api.location == ApiLocation.host && api.methods.isNotEmpty)); - for (final Class klass in root.classes) { _writeObjcSourceDataClassExtension(generatorOptions, indent, klass); } @@ -715,6 +711,56 @@ class ObjcSourceGenerator extends StructuredGenerator { }); } + @override + void writeGeneralUtilities( + ObjcOptions generatorOptions, + Root root, + Indent indent, { + required String dartPackageName, + }) { + final bool hasHostApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.host); + final bool hasFlutterApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.flutter); + + if (hasHostApi) { + _writeWrapError(indent); + indent.newln(); + } + if (hasFlutterApi) { + _writeCreateConnectionError(indent); + indent.newln(); + } + _writeGetNullableObjectAtIndex(indent); + } + + void _writeWrapError(Indent indent) { + indent.format(''' +static NSArray *wrapResult(id result, FlutterError *error) { +\tif (error) { +\t\treturn @[ +\t\t\terror.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] +\t\t]; +\t} +\treturn @[ result ?: [NSNull null] ]; +}'''); + } + + void _writeGetNullableObjectAtIndex(Indent indent) { + indent.format(''' +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { +\tid result = array[key]; +\treturn (result == [NSNull null]) ? nil : result; +}'''); + } + + void _writeCreateConnectionError(Indent indent) { + indent.format(''' +static FlutterError *createConnectionError(NSString *channelName) { +\treturn [FlutterError errorWithCode:@"channel-error" message:[NSString stringWithFormat:@"%@/%@/%@", @"Unable to establish connection on channel: '", channelName, @"'."] details:@""]; +}'''); + } + void _writeChannelApiBinding(ObjcOptions generatorOptions, Root root, Indent indent, String apiName, Method func, String channel) { void unpackArgs(String variable) { @@ -878,26 +924,6 @@ class ObjcSourceGenerator extends StructuredGenerator { }); } - void _writeObjcSourceHelperFunctions(Indent indent, - {required bool hasHostApiMethods}) { - if (hasHostApiMethods) { - indent.format(''' -static NSArray *wrapResult(id result, FlutterError *error) { -\tif (error) { -\t\treturn @[ -\t\t\terror.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] -\t\t]; -\t} -\treturn @[ result ?: [NSNull null] ]; -}'''); - } - indent.format(''' -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { -\tid result = array[key]; -\treturn (result == [NSNull null]) ? nil : result; -}'''); - } - void _writeObjcSourceDataClassExtension( ObjcOptions languageOptions, Indent indent, Class klass) { final String className = _className(languageOptions.prefix, klass.name); @@ -1095,12 +1121,13 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { root: root, )); indent.addScoped(' {', '}', () { + indent.writeln( + 'NSString *channelName = @"${makeChannelName(api, func, dartPackageName)}";'); indent.writeln('FlutterBasicMessageChannel *channel ='); indent.nest(1, () { indent.writeln('[FlutterBasicMessageChannel'); indent.nest(1, () { - indent.writeln( - 'messageChannelWithName:@"${makeChannelName(api, func, dartPackageName)}"'); + indent.writeln('messageChannelWithName:channelName'); indent.writeln('binaryMessenger:self.binaryMessenger'); indent.write( 'codec:${_getCodecGetterName(languageOptions.prefix, api.name)}()'); @@ -1138,7 +1165,7 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { }, addTrailingNewline: false); indent.addScoped('else {', '} ', () { indent.writeln( - 'completion($valueOnErrorResponse[FlutterError errorWithCode:@"channel-error" message:@"Unable to establish connection on channel." details:@""]);'); + 'completion(${valueOnErrorResponse}createConnectionError(channelName));'); }); }); }); diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index af96efd0205e..9fe23f2ce775 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -323,8 +323,6 @@ import FlutterMacOS }); } for (final Method func in api.methods) { - final String channelName = makeChannelName(api, func, dartPackageName); - addDocumentationComments( indent, func.documentationComments, _docCommentSpec); indent.writeScoped('${_getMethodSignature(func)} {', '}', () { @@ -338,38 +336,37 @@ import FlutterMacOS : '[${enumSafeArgNames.join(', ')}] as [Any?]'; const String channel = 'channel'; indent.writeln( - 'let $channel = FlutterBasicMessageChannel(name: "$channelName", binaryMessenger: binaryMessenger$codecArgumentString)'); + 'let channelName: String = "${makeChannelName(api, func, dartPackageName)}"'); + indent.writeln( + 'let $channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger$codecArgumentString)'); indent.write('$channel.sendMessage($sendArgument) '); - if (func.returnType.isVoid) { - indent.addScoped('{ _ in', '}', () { - indent.writeln('completion(.success(Void()))'); + + indent.addScoped('{ response in', '}', () { + indent.writeScoped( + 'guard let listResponse = response as? [Any?] else {', '}', () { + indent.writeln( + 'completion(.failure(createConnectionError(withChannelName:channelName)))'); + indent.writeln('return'); }); - } else { - indent.addScoped('{ response in', '}', () { - indent.writeScoped( - 'guard let listResponse = response as? [Any?] else {', '}', - () { - indent.writeln( - 'completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: "")))'); - indent.writeln('return'); - }); - indent.writeScoped('if (listResponse.count > 1) {', '} ', () { - indent.writeln('let code: String = listResponse[0] as! String'); - indent.writeln( - 'let message: String? = nilOrValue(listResponse[1])'); - indent.writeln( - 'let details: String? = nilOrValue(listResponse[2])'); + indent.writeScoped('if (listResponse.count > 1) {', '} ', () { + indent.writeln('let code: String = listResponse[0] as! String'); + indent.writeln( + 'let message: String? = nilOrValue(listResponse[1])'); + indent.writeln( + 'let details: String? = nilOrValue(listResponse[2])'); + indent.writeln( + 'completion(.failure(FlutterError(code: code, message: message, details: details)));'); + }, addTrailingNewline: false); + if (!func.returnType.isNullable && !func.returnType.isVoid) { + indent.addScoped('else if (listResponse[0] == nil) {', '} ', () { indent.writeln( - 'completion(.failure(FlutterError(code: code, message: message, details: details)));'); + 'completion(.failure(FlutterError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))'); }, addTrailingNewline: false); - if (!func.returnType.isNullable && !func.returnType.isVoid) { - indent.addScoped('else if (listResponse[0] == nil) {', '} ', - () { - indent.writeln( - 'completion(.failure(FlutterError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))'); - }, addTrailingNewline: false); - } - indent.addScoped('else {', '}', () { + } + indent.addScoped('else {', '}', () { + if (func.returnType.isVoid) { + indent.writeln('completion(.success(Void()))'); + } else { _writeDecodeCasting( root: root, indent: indent, @@ -378,9 +375,9 @@ import FlutterMacOS type: func.returnType, ); indent.writeln('completion(.success(result))'); - }); + } }); - } + }); }); } }); @@ -670,6 +667,7 @@ import FlutterMacOS Set? listEncodedEnumNames, }) { String castForceUnwrap(String value, TypeDeclaration type, Root root) { + assert(!type.isVoid); if (isEnum(root, type)) { String output = '${_swiftTypeForDartType(type)}(rawValue: $value as! Int)!'; @@ -780,6 +778,16 @@ private func nilOrValue(_ value: Any?) -> T? { }'''); } + void _writeCreateConnectionError(Indent indent) { + indent.newln(); + indent.writeScoped( + 'private func createConnectionError(withChannelName channelName: String) -> FlutterError {', + '}', () { + indent.writeln( + 'return FlutterError(code: "channel-error", message: "Unable to establish connection on channel: \'\\(channelName)\'.", details: "")'); + }); + } + @override void writeGeneralUtilities( SwiftOptions generatorOptions, @@ -787,9 +795,19 @@ private func nilOrValue(_ value: Any?) -> T? { Indent indent, { required String dartPackageName, }) { + final bool hasHostApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.host); + final bool hasFlutterApi = root.apis.any((Api api) => + api.methods.isNotEmpty && api.location == ApiLocation.flutter); + + if (hasHostApi) { + _writeWrapResult(indent); + _writeWrapError(indent); + } + if (hasFlutterApi) { + _writeCreateConnectionError(indent); + } _writeIsNullish(indent); - _writeWrapResult(indent); - _writeWrapError(indent); _writeNilOrValue(indent); } } @@ -882,7 +900,7 @@ String _getMethodSignature(Method func) { : _nullsafeSwiftTypeForDartType(func.returnType); if (func.arguments.isEmpty) { - return 'func ${func.name}(completion: @escaping (Result<$returnType, FlutterError>) -> Void) '; + return 'func ${func.name}(completion: @escaping (Result<$returnType, FlutterError>) -> Void)'; } else { final Iterable argTypes = func.arguments .map((NamedType e) => _nullsafeSwiftTypeForDartType(e.type)); @@ -895,7 +913,7 @@ String _getMethodSignature(Method func) { final String argsSignature = map3(argTypes, argLabels, argNames, (String type, String label, String name) => '$label $name: $type') .join(', '); - return 'func ${components.name}($argsSignature, completion: @escaping (Result<$returnType, FlutterError>) -> Void) '; + return 'func ${components.name}($argsSignature, completion: @escaping (Result<$returnType, FlutterError>) -> Void)'; } } 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 f23d543647d5..e508232de4c5 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 @@ -59,6 +59,12 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { return errorList; } + @NonNull + protected static FlutterError createConnectionError(@NonNull String channelName) { + return new FlutterError( + "channel-error", "Unable to establish connection on channel: " + channelName + ".", ""); + } + public enum AnEnum { ONE(0), TWO(1), @@ -3385,11 +3391,10 @@ public FlutterIntegrationCoreApi(@NonNull BinaryMessenger argBinaryMessenger) { * A no-op function taking no arguments and returning no value, to sanity test basic calling. */ public void noop(@NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( null, channelReply -> { @@ -3405,19 +3410,16 @@ public void noop(@NonNull Result result) { result.success(null); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Responds with an error from an async function returning a value. */ public void throwError(@NonNull NullableResult result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( null, channelReply -> { @@ -3435,19 +3437,16 @@ public void throwError(@NonNull NullableResult result) { result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Responds with an error from an async void function. */ public void throwErrorFromVoid(@NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( null, channelReply -> { @@ -3463,19 +3462,16 @@ public void throwErrorFromVoid(@NonNull Result result) { result.success(null); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed object, to test serialization and deserialization. */ public void echoAllTypes(@NonNull AllTypes everythingArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(everythingArg)), channelReply -> { @@ -3499,9 +3495,7 @@ public void echoAllTypes(@NonNull AllTypes everythingArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(everythingArg)), channelReply -> { @@ -3531,9 +3524,7 @@ public void echoAllNullableTypes( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } @@ -3547,11 +3538,10 @@ public void sendMultipleNullableTypes( @Nullable Long aNullableIntArg, @Nullable String aNullableStringArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList( Arrays.asList(aNullableBoolArg, aNullableIntArg, aNullableStringArg)), @@ -3576,19 +3566,16 @@ public void sendMultipleNullableTypes( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed boolean, to test serialization and deserialization. */ public void echoBool(@NonNull Boolean aBoolArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aBoolArg)), channelReply -> { @@ -3612,19 +3599,16 @@ public void echoBool(@NonNull Boolean aBoolArg, @NonNull Result result) result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed int, to test serialization and deserialization. */ public void echoInt(@NonNull Long anIntArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(anIntArg)), channelReply -> { @@ -3649,19 +3633,16 @@ public void echoInt(@NonNull Long anIntArg, @NonNull Result result) { result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed double, to test serialization and deserialization. */ public void echoDouble(@NonNull Double aDoubleArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aDoubleArg)), channelReply -> { @@ -3685,19 +3666,16 @@ public void echoDouble(@NonNull Double aDoubleArg, @NonNull Result resul result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed string, to test serialization and deserialization. */ public void echoString(@NonNull String aStringArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aStringArg)), channelReply -> { @@ -3721,19 +3699,16 @@ public void echoString(@NonNull String aStringArg, @NonNull Result resul result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed byte list, to test serialization and deserialization. */ public void echoUint8List(@NonNull byte[] aListArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aListArg)), channelReply -> { @@ -3757,19 +3732,16 @@ public void echoUint8List(@NonNull byte[] aListArg, @NonNull Result resu result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed list, to test serialization and deserialization. */ public void echoList(@NonNull List aListArg, @NonNull Result> result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aListArg)), channelReply -> { @@ -3793,20 +3765,17 @@ public void echoList(@NonNull List aListArg, @NonNull Result aMapArg, @NonNull Result> result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aMapArg)), channelReply -> { @@ -3830,19 +3799,16 @@ public void echoMap( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed enum to test serialization and deserialization. */ public void echoEnum(@NonNull AnEnum anEnumArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(anEnumArg.index)), channelReply -> { @@ -3866,20 +3832,17 @@ public void echoEnum(@NonNull AnEnum anEnumArg, @NonNull Result result) result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed boolean, to test serialization and deserialization. */ public void echoNullableBool( @Nullable Boolean aBoolArg, @NonNull NullableResult result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aBoolArg)), channelReply -> { @@ -3897,19 +3860,16 @@ public void echoNullableBool( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed int, to test serialization and deserialization. */ public void echoNullableInt(@Nullable Long anIntArg, @NonNull NullableResult result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(anIntArg)), channelReply -> { @@ -3928,20 +3888,17 @@ public void echoNullableInt(@Nullable Long anIntArg, @NonNull NullableResult result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aDoubleArg)), channelReply -> { @@ -3959,20 +3916,17 @@ public void echoNullableDouble( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed string, to test serialization and deserialization. */ public void echoNullableString( @Nullable String aStringArg, @NonNull NullableResult result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aStringArg)), channelReply -> { @@ -3990,20 +3944,17 @@ public void echoNullableString( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed byte list, to test serialization and deserialization. */ public void echoNullableUint8List( @Nullable byte[] aListArg, @NonNull NullableResult result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aListArg)), channelReply -> { @@ -4021,20 +3972,17 @@ public void echoNullableUint8List( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed list, to test serialization and deserialization. */ public void echoNullableList( @Nullable List aListArg, @NonNull NullableResult> result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aListArg)), channelReply -> { @@ -4052,9 +4000,7 @@ public void echoNullableList( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } @@ -4062,11 +4008,10 @@ public void echoNullableList( public void echoNullableMap( @Nullable Map aMapArg, @NonNull NullableResult> result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aMapArg)), channelReply -> { @@ -4084,20 +4029,17 @@ public void echoNullableMap( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed enum to test serialization and deserialization. */ public void echoNullableEnum( @Nullable AnEnum anEnumArg, @NonNull NullableResult result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList( Collections.singletonList(anEnumArg == null ? null : anEnumArg.index)), @@ -4117,9 +4059,7 @@ public void echoNullableEnum( result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } @@ -4128,11 +4068,10 @@ public void echoNullableEnum( * asynchronous calling. */ public void noopAsync(@NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( null, channelReply -> { @@ -4148,19 +4087,16 @@ public void noopAsync(@NonNull Result result) { result.success(null); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } /** Returns the passed in generic Object asynchronously. */ public void echoAsyncString(@NonNull String aStringArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aStringArg)), channelReply -> { @@ -4184,9 +4120,7 @@ public void echoAsyncString(@NonNull String aStringArg, @NonNull Result result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } @@ -4356,11 +4290,10 @@ public FlutterSmallApi(@NonNull BinaryMessenger argBinaryMessenger) { } public void echoWrappedList(@NonNull TestMessage msgArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(msgArg)), channelReply -> { @@ -4384,19 +4317,16 @@ public void echoWrappedList(@NonNull TestMessage msgArg, @NonNull Result result) { + final String channelName = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString"; BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString", - getCodec()); + new BasicMessageChannel<>(binaryMessenger, channelName, getCodec()); channel.send( new ArrayList(Collections.singletonList(aStringArg)), channelReply -> { @@ -4420,9 +4350,7 @@ public void echoString(@NonNull String aStringArg, @NonNull Result resul result.success(output); } } else { - result.error( - new FlutterError( - "channel-error", "Unable to establish connection on channel.", "")); + result.error(createConnectionError(channelName)); } }); } 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 bc3d0433db05..99bf5a54d137 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 @@ -17,16 +17,6 @@ #error File requires ARC to be enabled. #endif -@implementation AnEnumBox -- (instancetype)initWithValue:(AnEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - static NSArray *wrapResult(id result, FlutterError *error) { if (error) { return @[ @@ -35,11 +25,31 @@ - (instancetype)initWithValue:(AnEnum)value { } return @[ result ?: [NSNull null] ]; } + +static FlutterError *createConnectionError(NSString *channelName) { + return [FlutterError + errorWithCode:@"channel-error" + message:[NSString stringWithFormat:@"%@/%@/%@", + @"Unable to establish connection on channel: '", + channelName, @"'."] + details:@""]; +} + static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } +@implementation AnEnumBox +- (instancetype)initWithValue:(AnEnum)value { + self = [super init]; + if (self) { + _value = value; + } + return self; +} +@end + @interface AllTypes () + (AllTypes *)fromList:(NSArray *)list; + (nullable AllTypes *)nullableFromList:(NSArray *)list; @@ -2157,35 +2167,34 @@ - (instancetype)initWithBinaryMessenger:(NSObject *)bina return self; } - (void)noopWithCompletion:(void (^)(FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:nil - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion([FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:nil + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } + }]; } - (void)throwErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2198,44 +2207,40 @@ - (void)throwErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)throwErrorFromVoidWithCompletion:(void (^)(FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.throwErrorFromVoid" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:nil - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion([FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:nil + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } + }]; } - (void)echoAllTypes:(AllTypes *)arg_everything completion:(void (^)(AllTypes *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2248,21 +2253,19 @@ - (void)echoAllTypes:(AllTypes *)arg_everything completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoAllNullableTypes:(nullable AllNullableTypes *)arg_everything completion: (void (^)(AllNullableTypes *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoAllNullableTypes" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2275,10 +2278,7 @@ - (void)echoAllNullableTypes:(nullable AllNullableTypes *)arg_everything completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } @@ -2287,11 +2287,12 @@ - (void)sendMultipleNullableTypesABool:(nullable NSNumber *)arg_aNullableBool aString:(nullable NSString *)arg_aNullableString completion:(void (^)(AllNullableTypes *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.sendMultipleNullableTypes" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." + @"sendMultipleNullableTypes"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aNullableBool ?: [NSNull null], arg_aNullableInt ?: [NSNull null], arg_aNullableString ?: [NSNull null] @@ -2307,20 +2308,18 @@ - (void)sendMultipleNullableTypesABool:(nullable NSNumber *)arg_aNullableBool completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoBool:(BOOL)arg_aBool completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ @(arg_aBool) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2333,20 +2332,18 @@ - (void)echoBool:(BOOL)arg_aBool completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoInt:(NSInteger)arg_anInt completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ @(arg_anInt) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2359,20 +2356,18 @@ - (void)echoInt:(NSInteger)arg_anInt completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoDouble:(double)arg_aDouble completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ @(arg_aDouble) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2385,20 +2380,18 @@ - (void)echoDouble:(double)arg_aDouble completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoString:(NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2411,48 +2404,44 @@ - (void)echoString:(NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aList ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - FlutterStandardTypedData *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + FlutterStandardTypedData *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoList:(NSArray *)arg_aList completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aList ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2465,48 +2454,44 @@ - (void)echoList:(NSArray *)arg_aList completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoMap:(NSDictionary *)arg_aMap completion: (void (^)(NSDictionary *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aMap ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - NSDictionary *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + NSDictionary *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoEnum:(AnEnum)arg_anEnum completion:(void (^)(AnEnumBox *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ [NSNumber numberWithInteger:arg_anEnum] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2523,20 +2508,18 @@ - (void)echoEnum:(AnEnum)arg_anEnum completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableBool:(nullable NSNumber *)arg_aBool completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aBool ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2549,20 +2532,18 @@ - (void)echoNullableBool:(nullable NSNumber *)arg_aBool completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableInt:(nullable NSNumber *)arg_anInt completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_anInt ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2575,20 +2556,18 @@ - (void)echoNullableInt:(nullable NSNumber *)arg_anInt completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableDouble:(nullable NSNumber *)arg_aDouble completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoNullableDouble" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aDouble ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2601,20 +2580,18 @@ - (void)echoNullableDouble:(nullable NSNumber *)arg_aDouble completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableString:(nullable NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoNullableString" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2627,48 +2604,44 @@ - (void)echoNullableString:(nullable NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoNullableUint8List" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aList ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - FlutterStandardTypedData *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." + @"echoNullableUint8List"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + FlutterStandardTypedData *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoNullableList:(nullable NSArray *)arg_aList completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aList ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2681,48 +2654,44 @@ - (void)echoNullableList:(nullable NSArray *)arg_aList completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableMap:(nullable NSDictionary *)arg_aMap completion:(void (^)(NSDictionary *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aMap ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - NSDictionary *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + NSDictionary *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoNullableEnum:(nullable AnEnumBox *)arg_anEnum completion:(void (^)(AnEnumBox *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_anEnum == nil ? [NSNull null] : [NSNumber numberWithInteger:arg_anEnum.value] ] reply:^(NSArray *reply) { @@ -2740,44 +2709,40 @@ - (void)echoNullableEnum:(nullable AnEnumBox *)arg_anEnum completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:nil - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion([FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:nil + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } + }]; } - (void)echoAsyncString:(NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2790,10 +2755,7 @@ - (void)echoAsyncString:(NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } @@ -2934,11 +2896,12 @@ - (instancetype)initWithBinaryMessenger:(NSObject *)bina } - (void)echoWrappedList:(TestMessage *)arg_msg completion:(void (^)(TestMessage *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList" - binaryMessenger:self.binaryMessenger - codec:FlutterSmallApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterSmallApiGetCodec()]; [channel sendMessage:@[ arg_msg ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2951,20 +2914,17 @@ - (void)echoWrappedList:(TestMessage *)arg_msg completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoString:(NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString" - binaryMessenger:self.binaryMessenger - codec:FlutterSmallApiGetCodec()]; + NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterSmallApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2977,10 +2937,7 @@ - (void)echoString:(NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m index bc3d0433db05..99bf5a54d137 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/macos/Classes/CoreTests.gen.m @@ -17,16 +17,6 @@ #error File requires ARC to be enabled. #endif -@implementation AnEnumBox -- (instancetype)initWithValue:(AnEnum)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - static NSArray *wrapResult(id result, FlutterError *error) { if (error) { return @[ @@ -35,11 +25,31 @@ - (instancetype)initWithValue:(AnEnum)value { } return @[ result ?: [NSNull null] ]; } + +static FlutterError *createConnectionError(NSString *channelName) { + return [FlutterError + errorWithCode:@"channel-error" + message:[NSString stringWithFormat:@"%@/%@/%@", + @"Unable to establish connection on channel: '", + channelName, @"'."] + details:@""]; +} + static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } +@implementation AnEnumBox +- (instancetype)initWithValue:(AnEnum)value { + self = [super init]; + if (self) { + _value = value; + } + return self; +} +@end + @interface AllTypes () + (AllTypes *)fromList:(NSArray *)list; + (nullable AllTypes *)nullableFromList:(NSArray *)list; @@ -2157,35 +2167,34 @@ - (instancetype)initWithBinaryMessenger:(NSObject *)bina return self; } - (void)noopWithCompletion:(void (^)(FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:nil - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion([FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:nil + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } + }]; } - (void)throwErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:nil reply:^(NSArray *reply) { if (reply != nil) { @@ -2198,44 +2207,40 @@ - (void)throwErrorWithCompletion:(void (^)(id _Nullable, FlutterError *_Nullable completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)throwErrorFromVoidWithCompletion:(void (^)(FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.throwErrorFromVoid" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:nil - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion([FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:nil + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } + }]; } - (void)echoAllTypes:(AllTypes *)arg_everything completion:(void (^)(AllTypes *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2248,21 +2253,19 @@ - (void)echoAllTypes:(AllTypes *)arg_everything completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoAllNullableTypes:(nullable AllNullableTypes *)arg_everything completion: (void (^)(AllNullableTypes *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoAllNullableTypes" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_everything ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2275,10 +2278,7 @@ - (void)echoAllNullableTypes:(nullable AllNullableTypes *)arg_everything completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } @@ -2287,11 +2287,12 @@ - (void)sendMultipleNullableTypesABool:(nullable NSNumber *)arg_aNullableBool aString:(nullable NSString *)arg_aNullableString completion:(void (^)(AllNullableTypes *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.sendMultipleNullableTypes" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." + @"sendMultipleNullableTypes"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aNullableBool ?: [NSNull null], arg_aNullableInt ?: [NSNull null], arg_aNullableString ?: [NSNull null] @@ -2307,20 +2308,18 @@ - (void)sendMultipleNullableTypesABool:(nullable NSNumber *)arg_aNullableBool completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoBool:(BOOL)arg_aBool completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ @(arg_aBool) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2333,20 +2332,18 @@ - (void)echoBool:(BOOL)arg_aBool completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoInt:(NSInteger)arg_anInt completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ @(arg_anInt) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2359,20 +2356,18 @@ - (void)echoInt:(NSInteger)arg_anInt completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoDouble:(double)arg_aDouble completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ @(arg_aDouble) ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2385,20 +2380,18 @@ - (void)echoDouble:(double)arg_aDouble completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoString:(NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2411,48 +2404,44 @@ - (void)echoString:(NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoUint8List:(FlutterStandardTypedData *)arg_aList completion: (void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aList ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - FlutterStandardTypedData *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + FlutterStandardTypedData *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoList:(NSArray *)arg_aList completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aList ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2465,48 +2454,44 @@ - (void)echoList:(NSArray *)arg_aList completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoMap:(NSDictionary *)arg_aMap completion: (void (^)(NSDictionary *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aMap ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - NSDictionary *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + NSDictionary *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoEnum:(AnEnum)arg_anEnum completion:(void (^)(AnEnumBox *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ [NSNumber numberWithInteger:arg_anEnum] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2523,20 +2508,18 @@ - (void)echoEnum:(AnEnum)arg_anEnum completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableBool:(nullable NSNumber *)arg_aBool completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aBool ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2549,20 +2532,18 @@ - (void)echoNullableBool:(nullable NSNumber *)arg_aBool completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableInt:(nullable NSNumber *)arg_anInt completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_anInt ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2575,20 +2556,18 @@ - (void)echoNullableInt:(nullable NSNumber *)arg_anInt completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableDouble:(nullable NSNumber *)arg_aDouble completion:(void (^)(NSNumber *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoNullableDouble" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aDouble ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2601,20 +2580,18 @@ - (void)echoNullableDouble:(nullable NSNumber *)arg_aDouble completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableString:(nullable NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoNullableString" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2627,48 +2604,44 @@ - (void)echoNullableString:(nullable NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableUint8List:(nullable FlutterStandardTypedData *)arg_aList completion:(void (^)(FlutterStandardTypedData *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.pigeon_integration_tests." - @"FlutterIntegrationCoreApi.echoNullableUint8List" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aList ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - FlutterStandardTypedData *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." + @"echoNullableUint8List"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aList ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + FlutterStandardTypedData *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoNullableList:(nullable NSArray *)arg_aList completion:(void (^)(NSArray *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aList ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2681,48 +2654,44 @@ - (void)echoNullableList:(nullable NSArray *)arg_aList completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoNullableMap:(nullable NSDictionary *)arg_aMap completion:(void (^)(NSDictionary *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:@[ arg_aMap ?: [NSNull null] ] - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion(nil, [FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - NSDictionary *output = reply[0] == [NSNull null] ? nil : reply[0]; - completion(output, nil); - } - } else { - completion(nil, - [FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:@[ arg_aMap ?: [NSNull null] ] + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion(nil, [FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + NSDictionary *output = + reply[0] == [NSNull null] ? nil : reply[0]; + completion(output, nil); + } + } else { + completion(nil, createConnectionError(channelName)); + } + }]; } - (void)echoNullableEnum:(nullable AnEnumBox *)arg_anEnum completion:(void (^)(AnEnumBox *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_anEnum == nil ? [NSNull null] : [NSNumber numberWithInteger:arg_anEnum.value] ] reply:^(NSArray *reply) { @@ -2740,44 +2709,40 @@ - (void)echoNullableEnum:(nullable AnEnumBox *)arg_anEnum completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; - [channel - sendMessage:nil - reply:^(NSArray *reply) { - if (reply != nil) { - if (reply.count > 1) { - completion([FlutterError errorWithCode:reply[0] - message:reply[1] - details:reply[2]]); - } else { - completion(nil); - } - } else { - completion([FlutterError errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); - } - }]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; + [channel sendMessage:nil + reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] + message:reply[1] + details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } + }]; } - (void)echoAsyncString:(NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString" - binaryMessenger:self.binaryMessenger - codec:FlutterIntegrationCoreApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterIntegrationCoreApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2790,10 +2755,7 @@ - (void)echoAsyncString:(NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } @@ -2934,11 +2896,12 @@ - (instancetype)initWithBinaryMessenger:(NSObject *)bina } - (void)echoWrappedList:(TestMessage *)arg_msg completion:(void (^)(TestMessage *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList" - binaryMessenger:self.binaryMessenger - codec:FlutterSmallApiGetCodec()]; + NSString *channelName = + @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterSmallApiGetCodec()]; [channel sendMessage:@[ arg_msg ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2951,20 +2914,17 @@ - (void)echoWrappedList:(TestMessage *)arg_msg completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } - (void)echoString:(NSString *)arg_aString completion:(void (^)(NSString *_Nullable, FlutterError *_Nullable))completion { - FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName: - @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString" - binaryMessenger:self.binaryMessenger - codec:FlutterSmallApiGetCodec()]; + NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString"; + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel messageChannelWithName:channelName + binaryMessenger:self.binaryMessenger + codec:FlutterSmallApiGetCodec()]; [channel sendMessage:@[ arg_aString ?: [NSNull null] ] reply:^(NSArray *reply) { if (reply != nil) { @@ -2977,10 +2937,7 @@ - (void)echoString:(NSString *)arg_aString completion(output, nil); } } else { - completion(nil, [FlutterError - errorWithCode:@"channel-error" - message:@"Unable to establish connection on channel." - details:@""]); + completion(nil, createConnectionError(channelName)); } }]; } diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart index 843652082162..e48af86c9af9 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/background_platform_channels.gen.dart @@ -12,15 +12,11 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; -List wrapResponse( - {Object? result, PlatformException? error, bool empty = false}) { - if (empty) { - return []; - } - if (error == null) { - return [result]; - } - return [error.code, error.message, error.details]; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); } class BackgroundApi2Host { @@ -34,17 +30,17 @@ class BackgroundApi2Host { static const MessageCodec codec = StandardMessageCodec(); Future add(int arg_x, int arg_y) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.BackgroundApi2Host.add'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.BackgroundApi2Host.add', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_x, arg_y]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, 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 98a5b81a3f67..64b721bc2ee5 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 @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -319,16 +326,16 @@ class HostIntegrationCoreApi { /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. Future noop() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noop'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noop', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -342,17 +349,17 @@ class HostIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. Future echoAllTypes(AllTypes arg_everything) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_everything]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -371,16 +378,16 @@ class HostIntegrationCoreApi { /// Returns an error, to test error handling. Future throwError() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwError'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwError', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -394,16 +401,16 @@ class HostIntegrationCoreApi { /// Returns an error from a void function, to test error handling. Future throwErrorFromVoid() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwErrorFromVoid'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwErrorFromVoid', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -417,16 +424,16 @@ class HostIntegrationCoreApi { /// Returns a Flutter error, to test error handling. Future throwFlutterError() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwFlutterError'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwFlutterError', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -440,17 +447,17 @@ class HostIntegrationCoreApi { /// Returns passed in int. Future echoInt(int arg_anInt) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoInt', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anInt]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -469,17 +476,17 @@ class HostIntegrationCoreApi { /// Returns passed in double. Future echoDouble(double arg_aDouble) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoDouble'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoDouble', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aDouble]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -498,17 +505,17 @@ class HostIntegrationCoreApi { /// Returns the passed in boolean. Future echoBool(bool arg_aBool) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoBool'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoBool', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aBool]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -527,17 +534,17 @@ class HostIntegrationCoreApi { /// Returns the passed in string. Future echoString(String arg_aString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -556,17 +563,17 @@ class HostIntegrationCoreApi { /// Returns the passed in Uint8List. Future echoUint8List(Uint8List arg_aUint8List) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoUint8List'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoUint8List', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aUint8List]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -585,17 +592,17 @@ class HostIntegrationCoreApi { /// Returns the passed in generic Object. Future echoObject(Object arg_anObject) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoObject'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoObject', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anObject]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -614,17 +621,17 @@ class HostIntegrationCoreApi { /// Returns the passed list, to test serialization and deserialization. Future> echoList(List arg_aList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -643,17 +650,17 @@ class HostIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization. Future> echoMap(Map arg_aMap) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aMap]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -673,17 +680,17 @@ class HostIntegrationCoreApi { /// Returns the passed map to test nested class serialization and deserialization. Future echoClassWrapper( AllClassesWrapper arg_wrapper) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoClassWrapper'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoClassWrapper', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_wrapper]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -702,17 +709,17 @@ class HostIntegrationCoreApi { /// Returns the passed enum to test serialization and deserialization. Future echoEnum(AnEnum arg_anEnum) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoEnum'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoEnum', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anEnum.index]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -732,17 +739,17 @@ class HostIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. Future echoAllNullableTypes( AllNullableTypes? arg_everything) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllNullableTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAllNullableTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_everything]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -758,17 +765,17 @@ class HostIntegrationCoreApi { /// sending of nested objects. Future extractNestedNullableString( AllClassesWrapper arg_wrapper) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.extractNestedNullableString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.extractNestedNullableString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_wrapper]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -784,17 +791,17 @@ class HostIntegrationCoreApi { /// sending of nested objects. Future createNestedNullableString( String? arg_nullableString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.createNestedNullableString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.createNestedNullableString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_nullableString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -814,18 +821,18 @@ class HostIntegrationCoreApi { /// Returns passed in arguments of multiple types. Future sendMultipleNullableTypes(bool? arg_aNullableBool, int? arg_aNullableInt, String? arg_aNullableString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.sendMultipleNullableTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.sendMultipleNullableTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send( [arg_aNullableBool, arg_aNullableInt, arg_aNullableString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -844,17 +851,17 @@ class HostIntegrationCoreApi { /// Returns passed in int. Future echoNullableInt(int? arg_aNullableInt) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableInt', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableInt]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -868,17 +875,17 @@ class HostIntegrationCoreApi { /// Returns passed in double. Future echoNullableDouble(double? arg_aNullableDouble) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableDouble'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableDouble', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableDouble]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -892,17 +899,17 @@ class HostIntegrationCoreApi { /// Returns the passed in boolean. Future echoNullableBool(bool? arg_aNullableBool) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableBool'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableBool', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableBool]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -916,17 +923,17 @@ class HostIntegrationCoreApi { /// Returns the passed in string. Future echoNullableString(String? arg_aNullableString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -941,17 +948,17 @@ class HostIntegrationCoreApi { /// Returns the passed in Uint8List. Future echoNullableUint8List( Uint8List? arg_aNullableUint8List) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableUint8List'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableUint8List', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableUint8List]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -965,17 +972,17 @@ class HostIntegrationCoreApi { /// Returns the passed in generic Object. Future echoNullableObject(Object? arg_aNullableObject) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableObject'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableObject', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableObject]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -990,17 +997,17 @@ class HostIntegrationCoreApi { /// Returns the passed list, to test serialization and deserialization. Future?> echoNullableList( List? arg_aNullableList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1015,17 +1022,17 @@ class HostIntegrationCoreApi { /// Returns the passed map, to test serialization and deserialization. Future?> echoNullableMap( Map? arg_aNullableMap) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aNullableMap]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1038,17 +1045,17 @@ class HostIntegrationCoreApi { } Future echoNullableEnum(AnEnum? arg_anEnum) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableEnum'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoNullableEnum', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anEnum?.index]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1065,16 +1072,16 @@ class HostIntegrationCoreApi { /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. Future noopAsync() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noopAsync'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.noopAsync', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1088,17 +1095,17 @@ class HostIntegrationCoreApi { /// Returns passed in int asynchronously. Future echoAsyncInt(int arg_anInt) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncInt', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anInt]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1117,17 +1124,17 @@ class HostIntegrationCoreApi { /// Returns passed in double asynchronously. Future echoAsyncDouble(double arg_aDouble) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncDouble'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncDouble', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aDouble]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1146,17 +1153,17 @@ class HostIntegrationCoreApi { /// Returns the passed in boolean asynchronously. Future echoAsyncBool(bool arg_aBool) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncBool'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncBool', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aBool]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1175,17 +1182,17 @@ class HostIntegrationCoreApi { /// Returns the passed string asynchronously. Future echoAsyncString(String arg_aString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1204,17 +1211,17 @@ class HostIntegrationCoreApi { /// Returns the passed in Uint8List asynchronously. Future echoAsyncUint8List(Uint8List arg_aUint8List) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncUint8List'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncUint8List', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aUint8List]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1233,17 +1240,17 @@ class HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. Future echoAsyncObject(Object arg_anObject) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncObject'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncObject', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anObject]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1262,17 +1269,17 @@ class HostIntegrationCoreApi { /// Returns the passed list, to test asynchronous serialization and deserialization. Future> echoAsyncList(List arg_aList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1292,17 +1299,17 @@ class HostIntegrationCoreApi { /// Returns the passed map, to test asynchronous serialization and deserialization. Future> echoAsyncMap( Map arg_aMap) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aMap]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1321,17 +1328,17 @@ class HostIntegrationCoreApi { /// Returns the passed enum, to test asynchronous serialization and deserialization. Future echoAsyncEnum(AnEnum arg_anEnum) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncEnum'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncEnum', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anEnum.index]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1350,16 +1357,16 @@ class HostIntegrationCoreApi { /// Responds with an error from an async function returning a value. Future throwAsyncError() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncError'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncError', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1373,16 +1380,16 @@ class HostIntegrationCoreApi { /// Responds with an error from an async void function. Future throwAsyncErrorFromVoid() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncErrorFromVoid'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncErrorFromVoid', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1396,16 +1403,16 @@ class HostIntegrationCoreApi { /// Responds with a Flutter error from an async function returning a value. Future throwAsyncFlutterError() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncFlutterError'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.throwAsyncFlutterError', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1419,17 +1426,17 @@ class HostIntegrationCoreApi { /// Returns the passed object, to test async serialization and deserialization. Future echoAsyncAllTypes(AllTypes arg_everything) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncAllTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncAllTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_everything]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1449,17 +1456,17 @@ class HostIntegrationCoreApi { /// Returns the passed object, to test serialization and deserialization. Future echoAsyncNullableAllNullableTypes( AllNullableTypes? arg_everything) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableAllNullableTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableAllNullableTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_everything]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1473,17 +1480,17 @@ class HostIntegrationCoreApi { /// Returns passed in int asynchronously. Future echoAsyncNullableInt(int? arg_anInt) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableInt', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anInt]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1497,17 +1504,17 @@ class HostIntegrationCoreApi { /// Returns passed in double asynchronously. Future echoAsyncNullableDouble(double? arg_aDouble) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableDouble'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableDouble', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aDouble]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1521,17 +1528,17 @@ class HostIntegrationCoreApi { /// Returns the passed in boolean asynchronously. Future echoAsyncNullableBool(bool? arg_aBool) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableBool'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableBool', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aBool]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1545,17 +1552,17 @@ class HostIntegrationCoreApi { /// Returns the passed string asynchronously. Future echoAsyncNullableString(String? arg_aString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1570,17 +1577,17 @@ class HostIntegrationCoreApi { /// Returns the passed in Uint8List asynchronously. Future echoAsyncNullableUint8List( Uint8List? arg_aUint8List) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableUint8List'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableUint8List', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aUint8List]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1594,17 +1601,17 @@ class HostIntegrationCoreApi { /// Returns the passed in generic Object asynchronously. Future echoAsyncNullableObject(Object? arg_anObject) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableObject'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableObject', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anObject]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1618,17 +1625,17 @@ class HostIntegrationCoreApi { /// Returns the passed list, to test asynchronous serialization and deserialization. Future?> echoAsyncNullableList(List? arg_aList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1643,17 +1650,17 @@ class HostIntegrationCoreApi { /// Returns the passed map, to test asynchronous serialization and deserialization. Future?> echoAsyncNullableMap( Map? arg_aMap) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aMap]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1667,17 +1674,17 @@ class HostIntegrationCoreApi { /// Returns the passed enum, to test asynchronous serialization and deserialization. Future echoAsyncNullableEnum(AnEnum? arg_anEnum) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableEnum'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.echoAsyncNullableEnum', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anEnum?.index]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1692,16 +1699,16 @@ class HostIntegrationCoreApi { } Future callFlutterNoop() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterNoop'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterNoop', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1714,16 +1721,16 @@ class HostIntegrationCoreApi { } Future callFlutterThrowError() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterThrowError'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterThrowError', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1736,16 +1743,16 @@ class HostIntegrationCoreApi { } Future callFlutterThrowErrorFromVoid() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterThrowErrorFromVoid'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterThrowErrorFromVoid', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1758,17 +1765,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoAllTypes(AllTypes arg_everything) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoAllTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoAllTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_everything]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1787,17 +1794,17 @@ class HostIntegrationCoreApi { Future callFlutterEchoAllNullableTypes( AllNullableTypes? arg_everything) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoAllNullableTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoAllNullableTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_everything]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1813,18 +1820,18 @@ class HostIntegrationCoreApi { bool? arg_aNullableBool, int? arg_aNullableInt, String? arg_aNullableString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterSendMultipleNullableTypes', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send( [arg_aNullableBool, arg_aNullableInt, arg_aNullableString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1842,17 +1849,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoBool(bool arg_aBool) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoBool'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoBool', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aBool]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1870,17 +1877,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoInt(int arg_anInt) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoInt', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anInt]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1898,17 +1905,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoDouble(double arg_aDouble) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoDouble'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoDouble', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aDouble]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1926,17 +1933,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoString(String arg_aString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1954,17 +1961,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoUint8List(Uint8List arg_aList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoUint8List'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoUint8List', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -1982,17 +1989,17 @@ class HostIntegrationCoreApi { } Future> callFlutterEchoList(List arg_aList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2011,17 +2018,17 @@ class HostIntegrationCoreApi { Future> callFlutterEchoMap( Map arg_aMap) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aMap]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2039,17 +2046,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoEnum(AnEnum arg_anEnum) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoEnum'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoEnum', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anEnum.index]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2067,17 +2074,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoNullableBool(bool? arg_aBool) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableBool'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableBool', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aBool]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2090,17 +2097,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoNullableInt(int? arg_anInt) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableInt', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anInt]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2113,17 +2120,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoNullableDouble(double? arg_aDouble) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableDouble'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableDouble', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aDouble]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2136,17 +2143,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoNullableString(String? arg_aString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2160,17 +2167,17 @@ class HostIntegrationCoreApi { Future callFlutterEchoNullableUint8List( Uint8List? arg_aList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableUint8List'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableUint8List', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2184,17 +2191,17 @@ class HostIntegrationCoreApi { Future?> callFlutterEchoNullableList( List? arg_aList) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aList]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2208,17 +2215,17 @@ class HostIntegrationCoreApi { Future?> callFlutterEchoNullableMap( Map? arg_aMap) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aMap]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -2231,17 +2238,17 @@ class HostIntegrationCoreApi { } Future callFlutterEchoNullableEnum(AnEnum? arg_anEnum) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableEnum'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostIntegrationCoreApi.callFlutterEchoNullableEnum', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_anEnum?.index]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -3008,16 +3015,16 @@ class HostTrivialApi { static const MessageCodec codec = StandardMessageCodec(); Future noop() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostTrivialApi.noop'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostTrivialApi.noop', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -3042,16 +3049,17 @@ class HostSmallApi { static const MessageCodec codec = StandardMessageCodec(); Future echo(String arg_aString) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_aString]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -3069,16 +3077,16 @@ class HostSmallApi { } Future voidVoid() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart index 2374bdb9bff5..9f3c469c9b86 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/enum.gen.dart @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -94,16 +101,17 @@ class EnumApi2Host { /// This comment is to test method documentation comments. Future echo(DataWithEnum arg_data) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Host.echo'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Host.echo', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_data]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart index 4b8b89e555f4..8b149d7942e0 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/flutter_unittests.gen.dart @@ -12,15 +12,11 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; -List wrapResponse( - {Object? result, PlatformException? error, bool empty = false}) { - if (empty) { - return []; - } - if (error == null) { - return [result]; - } - return [error.code, error.message, error.details]; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); } class FlutterSearchRequest { @@ -160,16 +156,17 @@ class Api { static const MessageCodec codec = _ApiCodec(); Future search(FlutterSearchRequest arg_request) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.Api.search'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.Api.search', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_request]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -188,16 +185,17 @@ class Api { Future doSearches( FlutterSearchRequests arg_request) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.Api.doSearches'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.Api.doSearches', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_request]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -215,16 +213,17 @@ class Api { } Future echo(FlutterSearchRequests arg_requests) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.Api.echo'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.Api.echo', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_requests]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -242,16 +241,17 @@ class Api { } Future anInt(int arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.Api.anInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.Api.anInt', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart index 7ed95ca1878f..fa0084706ff7 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/message.gen.dart @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -182,16 +189,16 @@ class MessageApi { /// /// This comment also tests multiple line comments. Future initialize() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.initialize', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -205,16 +212,17 @@ class MessageApi { /// This comment is to test method documentation comments. Future search(MessageSearchRequest arg_request) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.MessageApi.search', codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_request]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -280,17 +288,17 @@ class MessageNestedApi { /// /// This comment also tests multiple line comments. Future search(MessageNested arg_nested) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.MessageNestedApi.search', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_nested]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart index a9f4c8343b75..2922865d9aa7 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/multiple_arity.gen.dart @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -34,17 +41,17 @@ class MultipleArityHostApi { static const MessageCodec codec = StandardMessageCodec(); Future subtract(int arg_x, int arg_y) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.MultipleArityHostApi.subtract'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.MultipleArityHostApi.subtract', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_x, arg_y]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart index a00148ba2b6f..3a40af187168 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/non_null_fields.gen.dart @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -161,17 +168,17 @@ class NonNullFieldHostApi { Future search( NonNullFieldSearchRequest arg_nested) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.NonNullFieldHostApi.search'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.NonNullFieldHostApi.search', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_nested]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart index 5adf669e7631..863897535cb2 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/null_fields.gen.dart @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -139,17 +146,17 @@ class NullFieldsHostApi { Future search( NullFieldsSearchRequest arg_nested) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.NullFieldsHostApi.search'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.NullFieldsHostApi.search', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_nested]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart index 8b5c7011f1f2..c7f71206ee30 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/nullable_returns.gen.dart @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -34,16 +41,16 @@ class NullableReturnHostApi { static const MessageCodec codec = StandardMessageCodec(); Future doit() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.NullableReturnHostApi.doit'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.NullableReturnHostApi.doit', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -98,17 +105,17 @@ class NullableArgHostApi { static const MessageCodec codec = StandardMessageCodec(); Future doit(int? arg_x) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.NullableArgHostApi.doit'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.NullableArgHostApi.doit', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_x]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -172,16 +179,16 @@ class NullableCollectionReturnHostApi { static const MessageCodec codec = StandardMessageCodec(); Future?> doit() async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionReturnHostApi.doit'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionReturnHostApi.doit', - codec, - binaryMessenger: _binaryMessenger); + channelName, + 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.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -236,17 +243,17 @@ class NullableCollectionArgHostApi { static const MessageCodec codec = StandardMessageCodec(); Future> doit(List? arg_x) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionArgHostApi.doit'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.NullableCollectionArgHostApi.doit', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_x]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart index 8dd4d79b2b5e..d5387984bab4 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/primitive.gen.dart @@ -12,6 +12,13 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + List wrapResponse( {Object? result, PlatformException? error, bool empty = false}) { if (empty) { @@ -34,17 +41,17 @@ class PrimitiveHostApi { static const MessageCodec codec = StandardMessageCodec(); Future anInt(int arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -62,17 +69,17 @@ class PrimitiveHostApi { } Future aBool(bool arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBool'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBool', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -90,17 +97,17 @@ class PrimitiveHostApi { } Future aString(String arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aString'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aString', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -118,17 +125,17 @@ class PrimitiveHostApi { } Future aDouble(double arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aDouble'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aDouble', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -146,17 +153,17 @@ class PrimitiveHostApi { } Future> aMap(Map arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -174,17 +181,17 @@ class PrimitiveHostApi { } Future> aList(List arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -202,17 +209,17 @@ class PrimitiveHostApi { } Future anInt32List(Int32List arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt32List'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt32List', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -230,17 +237,17 @@ class PrimitiveHostApi { } Future> aBoolList(List arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBoolList'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBoolList', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, @@ -258,17 +265,17 @@ class PrimitiveHostApi { } Future> aStringIntMap(Map arg_value) async { + const String channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aStringIntMap'; final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aStringIntMap', - codec, - binaryMessenger: _binaryMessenger); + channelName, + codec, + binaryMessenger: _binaryMessenger, + ); final List? replyList = await channel.send([arg_value]) as List?; if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); + throw _createConnectionError(channelName); } else if (replyList.length > 1) { throw PlatformException( code: replyList[0]! as String, 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 86ec67552400..502644b5efb8 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 @@ -35,6 +35,9 @@ private fun wrapError(exception: Throwable): List { } } +private fun createConnectionError(channelName: String): FlutterError { + return FlutterError("channel-error", "Unable to establish connection on channel: '$channelName'.", "")} + /** * Error class for passing custom error details to Flutter via a thrown PlatformException. * @property code The error code. @@ -1922,7 +1925,8 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { * test basic calling. */ fun noop(callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(null) { if (it is List<*>) { if (it.size > 1) { @@ -1931,13 +1935,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(Unit)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Responds with an error from an async function returning a value. */ fun throwError(callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(null) { if (it is List<*>) { if (it.size > 1) { @@ -1947,13 +1952,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Responds with an error from an async void function. */ fun throwErrorFromVoid(callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(null) { if (it is List<*>) { if (it.size > 1) { @@ -1962,13 +1968,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(Unit)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed object, to test serialization and deserialization. */ fun echoAllTypes(everythingArg: AllTypes, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(everythingArg)) { if (it is List<*>) { if (it.size > 1) { @@ -1980,13 +1987,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed object, to test serialization and deserialization. */ fun echoAllNullableTypes(everythingArg: AllNullableTypes?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(everythingArg)) { if (it is List<*>) { if (it.size > 1) { @@ -1996,7 +2004,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } @@ -2006,7 +2014,8 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { * Tests multiple-arity FlutterApi handling. */ fun sendMultipleNullableTypes(aNullableBoolArg: Boolean?, aNullableIntArg: Long?, aNullableStringArg: String?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aNullableBoolArg, aNullableIntArg, aNullableStringArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2018,13 +2027,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed boolean, to test serialization and deserialization. */ fun echoBool(aBoolArg: Boolean, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aBoolArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2036,13 +2046,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed int, to test serialization and deserialization. */ fun echoInt(anIntArg: Long, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(anIntArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2054,13 +2065,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed double, to test serialization and deserialization. */ fun echoDouble(aDoubleArg: Double, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aDoubleArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2072,13 +2084,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed string, to test serialization and deserialization. */ fun echoString(aStringArg: String, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2090,13 +2103,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed byte list, to test serialization and deserialization. */ fun echoUint8List(aListArg: ByteArray, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2108,13 +2122,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed list, to test serialization and deserialization. */ fun echoList(aListArg: List, callback: (Result>) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2126,13 +2141,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed map, to test serialization and deserialization. */ fun echoMap(aMapArg: Map, callback: (Result>) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aMapArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2144,13 +2160,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed enum to test serialization and deserialization. */ fun echoEnum(anEnumArg: AnEnum, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(anEnumArg.raw)) { if (it is List<*>) { if (it.size > 1) { @@ -2162,13 +2179,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed boolean, to test serialization and deserialization. */ fun echoNullableBool(aBoolArg: Boolean?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aBoolArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2178,13 +2196,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed int, to test serialization and deserialization. */ fun echoNullableInt(anIntArg: Long?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(anIntArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2194,13 +2213,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed double, to test serialization and deserialization. */ fun echoNullableDouble(aDoubleArg: Double?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aDoubleArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2210,13 +2230,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed string, to test serialization and deserialization. */ fun echoNullableString(aStringArg: String?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2226,13 +2247,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed byte list, to test serialization and deserialization. */ fun echoNullableUint8List(aListArg: ByteArray?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2242,13 +2264,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed list, to test serialization and deserialization. */ fun echoNullableList(aListArg: List?, callback: (Result?>) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aListArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2258,13 +2281,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed map, to test serialization and deserialization. */ fun echoNullableMap(aMapArg: Map?, callback: (Result?>) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aMapArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2274,13 +2298,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed enum to test serialization and deserialization. */ fun echoNullableEnum(anEnumArg: AnEnum?, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(anEnumArg?.raw)) { if (it is List<*>) { if (it.size > 1) { @@ -2292,7 +2317,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } @@ -2301,7 +2326,8 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { * test basic asynchronous calling. */ fun noopAsync(callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(null) { if (it is List<*>) { if (it.size > 1) { @@ -2310,13 +2336,14 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(Unit)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } /** Returns the passed in generic Object asynchronously. */ fun echoAsyncString(aStringArg: String, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2328,7 +2355,7 @@ class FlutterIntegrationCoreApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } @@ -2463,7 +2490,8 @@ class FlutterSmallApi(private val binaryMessenger: BinaryMessenger) { } } fun echoWrappedList(msgArg: TestMessage, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(msgArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2475,12 +2503,13 @@ class FlutterSmallApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } fun echoString(aStringArg: String, callback: (Result) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString", codec) + val channelName = "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(aStringArg)) { if (it is List<*>) { if (it.size > 1) { @@ -2492,7 +2521,7 @@ class FlutterSmallApi(private val binaryMessenger: BinaryMessenger) { callback(Result.success(output)); } } else { - callback(Result.failure(FlutterError("channel-error", "Unable to establish connection on channel.", ""))); + callback(Result.failure(createConnectionError(channelName))); } } } 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 8b83e3d17717..40aee78946de 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 @@ -14,10 +14,6 @@ import FlutterMacOS #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil -} - private func wrapResult(_ result: Any?) -> [Any?] { return [result] } @@ -37,6 +33,14 @@ private func wrapError(_ error: Any) -> [Any?] { ] } +private func createConnectionError(withChannelName channelName: String) -> FlutterError { + return FlutterError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? @@ -1743,56 +1747,56 @@ class FlutterIntegrationCoreApiCodec: FlutterStandardMessageCodec { protocol FlutterIntegrationCoreApiProtocol { /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) + func noop(completion: @escaping (Result) -> Void) /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) + func throwError(completion: @escaping (Result) -> Void) /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) + func throwErrorFromVoid(completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) + func noopAsync(completion: @escaping (Result) -> Void) /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -1804,18 +1808,31 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion(.success(Void())) + func noop(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } } } /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError", binaryMessenger: binaryMessenger, codec: codec) + func throwError(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1830,18 +1847,31 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion(.success(Void())) + func throwErrorFromVoid(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } } } /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1858,11 +1888,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1879,11 +1910,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1900,11 +1932,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1921,11 +1954,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1942,11 +1976,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1963,11 +1998,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1984,11 +2020,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2005,11 +2042,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2026,11 +2064,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2047,11 +2086,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2068,11 +2108,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2087,11 +2128,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2106,11 +2148,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2125,11 +2168,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2144,11 +2188,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2163,11 +2208,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2182,11 +2228,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2201,11 +2248,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg?.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2221,18 +2269,31 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion(.success(Void())) + func noopAsync(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } } } /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2363,8 +2424,8 @@ class FlutterSmallApiCodec: FlutterStandardMessageCodec { /// /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. protocol FlutterSmallApiProtocol { - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterSmallApi: FlutterSmallApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -2374,11 +2435,12 @@ class FlutterSmallApi: FlutterSmallApiProtocol { var codec: FlutterStandardMessageCodec { return FlutterSmallApiCodec.shared } - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([msgArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2394,11 +2456,12 @@ class FlutterSmallApi: FlutterSmallApiProtocol { } } } - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { 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 8b83e3d17717..40aee78946de 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 @@ -14,10 +14,6 @@ import FlutterMacOS #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil -} - private func wrapResult(_ result: Any?) -> [Any?] { return [result] } @@ -37,6 +33,14 @@ private func wrapError(_ error: Any) -> [Any?] { ] } +private func createConnectionError(withChannelName channelName: String) -> FlutterError { + return FlutterError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? @@ -1743,56 +1747,56 @@ class FlutterIntegrationCoreApiCodec: FlutterStandardMessageCodec { protocol FlutterIntegrationCoreApiProtocol { /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) + func noop(completion: @escaping (Result) -> Void) /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) + func throwError(completion: @escaping (Result) -> Void) /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) + func throwErrorFromVoid(completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) + func noopAsync(completion: @escaping (Result) -> Void) /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -1804,18 +1808,31 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic calling. - func noop(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion(.success(Void())) + func noop(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noop" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } } } /// Responds with an error from an async function returning a value. - func throwError(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError", binaryMessenger: binaryMessenger, codec: codec) + func throwError(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwError" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1830,18 +1847,31 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Responds with an error from an async void function. - func throwErrorFromVoid(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion(.success(Void())) + func throwErrorFromVoid(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.throwErrorFromVoid" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } } } /// Returns the passed object, to test serialization and deserialization. - func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ everythingArg: AllTypes, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllTypes" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1858,11 +1888,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed object, to test serialization and deserialization. - func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ everythingArg: AllNullableTypes?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAllNullableTypes" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([everythingArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1879,11 +1910,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { /// Returns passed in arguments of multiple types. /// /// Tests multiple-arity FlutterApi handling. - func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes", binaryMessenger: binaryMessenger, codec: codec) + func sendMultipleNullableTypes(aBool aNullableBoolArg: Bool?, anInt aNullableIntArg: Int64?, aString aNullableStringArg: String?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.sendMultipleNullableTypes" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aNullableBoolArg, aNullableIntArg, aNullableStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1900,11 +1932,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aBoolArg: Bool, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoBool" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1921,11 +1954,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ anIntArg: Int64, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoInt" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1942,11 +1976,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aDoubleArg: Double, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoDouble" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1963,11 +1998,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -1984,11 +2020,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aListArg: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoUint8List" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2005,11 +2042,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aListArg: [Any?], completion: @escaping (Result<[Any?], FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoList" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2026,11 +2064,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aMapArg: [String?: Any?], completion: @escaping (Result<[String?: Any?], FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoMap" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2047,11 +2086,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ anEnumArg: AnEnum, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoEnum" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2068,11 +2108,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed boolean, to test serialization and deserialization. - func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aBoolArg: Bool?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableBool" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aBoolArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2087,11 +2128,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed int, to test serialization and deserialization. - func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ anIntArg: Int64?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableInt" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anIntArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2106,11 +2148,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed double, to test serialization and deserialization. - func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aDoubleArg: Double?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableDouble" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aDoubleArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2125,11 +2168,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed string, to test serialization and deserialization. - func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aStringArg: String?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2144,11 +2188,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed byte list, to test serialization and deserialization. - func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aListArg: FlutterStandardTypedData?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableUint8List" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2163,11 +2208,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed list, to test serialization and deserialization. - func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aListArg: [Any?]?, completion: @escaping (Result<[Any?]?, FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableList" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aListArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2182,11 +2228,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed map, to test serialization and deserialization. - func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ aMapArg: [String?: Any?]?, completion: @escaping (Result<[String?: Any?]?, FlutterError>) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableMap" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aMapArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2201,11 +2248,12 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } } /// Returns the passed enum to test serialization and deserialization. - func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum", binaryMessenger: binaryMessenger, codec: codec) + func echoNullable(_ anEnumArg: AnEnum?, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoNullableEnum" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([anEnumArg?.rawValue] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2221,18 +2269,31 @@ class FlutterIntegrationCoreApi: FlutterIntegrationCoreApiProtocol { } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - func noopAsync(completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion(.success(Void())) + func noopAsync(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.noopAsync" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } } } /// Returns the passed in generic Object asynchronously. - func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString", binaryMessenger: binaryMessenger, codec: codec) + func echoAsync(_ aStringArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2363,8 +2424,8 @@ class FlutterSmallApiCodec: FlutterStandardMessageCodec { /// /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. protocol FlutterSmallApiProtocol { - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) } class FlutterSmallApi: FlutterSmallApiProtocol { private let binaryMessenger: FlutterBinaryMessenger @@ -2374,11 +2435,12 @@ class FlutterSmallApi: FlutterSmallApiProtocol { var codec: FlutterStandardMessageCodec { return FlutterSmallApiCodec.shared } - func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ msgArg: TestMessage, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoWrappedList" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([msgArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { @@ -2394,11 +2456,12 @@ class FlutterSmallApi: FlutterSmallApiProtocol { } } } - func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString", binaryMessenger: binaryMessenger, codec: codec) + func echo(_ aStringArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([aStringArg] as [Any?]) { response in guard let listResponse = response as? [Any?] else { - completion(.failure(FlutterError(code: "channel-error", message: "Unable to establish connection on channel.", details: ""))) + completion(.failure(createConnectionError(withChannelName:channelName))) return } if (listResponse.count > 1) { 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 445911f7b306..6acd3cb1866a 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 @@ -25,6 +25,13 @@ using flutter::EncodableList; using flutter::EncodableMap; using flutter::EncodableValue; +FlutterError CreateConnectionError(const std::string channel_name) { + return FlutterError( + "channel-error", + "Unable to establish connection on channel: '" + channel_name + "'.", + EncodableValue("")); +} + // AllTypes AllTypes::AllTypes(bool a_bool, int64_t an_int, int64_t an_int64, @@ -3617,182 +3624,177 @@ const flutter::StandardMessageCodec& FlutterIntegrationCoreApi::GetCodec() { void FlutterIntegrationCoreApi::Noop( std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "noop", - &GetCodec()); + "noop"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - on_success(); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + on_success(); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::ThrowError( std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "throwError", - &GetCodec()); + "throwError"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto* return_value = &list_return_value->at(0); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto* return_value = &list_return_value->at(0); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::ThrowErrorFromVoid( std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "throwErrorFromVoid", - &GetCodec()); + "throwErrorFromVoid"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - on_success(); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + on_success(); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoAllTypes( const AllTypes& everything_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoAllTypes", - &GetCodec()); + "echoAllTypes"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ CustomEncodableValue(everything_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = std::any_cast( - std::get(list_return_value->at(0))); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = std::any_cast( + std::get(list_return_value->at(0))); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoAllNullableTypes( const AllNullableTypes* everything_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoAllNullableTypes", - &GetCodec()); + "echoAllNullableTypes"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ everything_arg ? CustomEncodableValue(*everything_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto* return_value = &(std::any_cast( - std::get(list_return_value->at(0)))); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto* return_value = &(std::any_cast( + std::get(list_return_value->at(0)))); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::SendMultipleNullableTypes( @@ -3800,11 +3802,11 @@ void FlutterIntegrationCoreApi::SendMultipleNullableTypes( const std::string* a_nullable_string_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "sendMultipleNullableTypes", - &GetCodec()); + "sendMultipleNullableTypes"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_nullable_bool_arg ? EncodableValue(*a_nullable_bool_arg) : EncodableValue(), @@ -3813,119 +3815,117 @@ void FlutterIntegrationCoreApi::SendMultipleNullableTypes( a_nullable_string_arg ? EncodableValue(*a_nullable_string_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = std::any_cast( - std::get(list_return_value->at(0))); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = std::any_cast( + std::get(list_return_value->at(0))); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoBool( bool a_bool_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoBool", - &GetCodec()); + "echoBool"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_bool_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = std::get(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = std::get(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoInt( int64_t an_int_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoInt", - &GetCodec()); + "echoInt"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(an_int_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const int64_t return_value = list_return_value->at(0).LongValue(); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const int64_t return_value = list_return_value->at(0).LongValue(); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoDouble( double a_double_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoDouble", - &GetCodec()); + "echoDouble"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_double_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), + channel->Send(encoded_api_arguments, [channel_name, + on_success = std::move(on_success), on_error = std::move(on_error)]( const uint8_t* reply, size_t reply_size) { @@ -3944,9 +3944,7 @@ void FlutterIntegrationCoreApi::EchoDouble( on_success(return_value); } } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); + on_error(CreateConnectionError(channel_name)); } }); } @@ -3955,208 +3953,204 @@ void FlutterIntegrationCoreApi::EchoString( const std::string& a_string_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoString", - &GetCodec()); + "echoString"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_string_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = - std::get(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = + std::get(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoUint8List( const std::vector& a_list_arg, std::function&)>&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoUint8List", - &GetCodec()); + "echoUint8List"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_list_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = - std::get>(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = + std::get>(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoList( const EncodableList& a_list_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoList", - &GetCodec()); + "echoList"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_list_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = - std::get(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = + std::get(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoMap( const EncodableMap& a_map_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoMap", - &GetCodec()); + "echoMap"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_map_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = - std::get(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = + std::get(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoEnum( const AnEnum& an_enum_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoEnum", - &GetCodec()); + "echoEnum"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue((int)an_enum_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const AnEnum& return_value = - (AnEnum)list_return_value->at(0).LongValue(); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const AnEnum& return_value = + (AnEnum)list_return_value->at(0).LongValue(); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoNullableBool( const bool* a_bool_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableBool", - &GetCodec()); + "echoNullableBool"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_bool_arg ? EncodableValue(*a_bool_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), + channel->Send(encoded_api_arguments, [channel_name, + on_success = std::move(on_success), on_error = std::move(on_error)]( const uint8_t* reply, size_t reply_size) { @@ -4175,9 +4169,7 @@ void FlutterIntegrationCoreApi::EchoNullableBool( on_success(return_value); } } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); + on_error(CreateConnectionError(channel_name)); } }); } @@ -4185,15 +4177,16 @@ void FlutterIntegrationCoreApi::EchoNullableBool( void FlutterIntegrationCoreApi::EchoNullableInt( const int64_t* an_int_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableInt", - &GetCodec()); + "echoNullableInt"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ an_int_arg ? EncodableValue(*an_int_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), + channel->Send(encoded_api_arguments, [channel_name, + on_success = std::move(on_success), on_error = std::move(on_error)]( const uint8_t* reply, size_t reply_size) { @@ -4217,9 +4210,7 @@ void FlutterIntegrationCoreApi::EchoNullableInt( on_success(return_value); } } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); + on_error(CreateConnectionError(channel_name)); } }); } @@ -4227,209 +4218,205 @@ void FlutterIntegrationCoreApi::EchoNullableInt( void FlutterIntegrationCoreApi::EchoNullableDouble( const double* a_double_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableDouble", - &GetCodec()); + "echoNullableDouble"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_double_arg ? EncodableValue(*a_double_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto* return_value = - std::get_if(&list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto* return_value = + std::get_if(&list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoNullableString( const std::string* a_string_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableString", - &GetCodec()); + "echoNullableString"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_string_arg ? EncodableValue(*a_string_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto* return_value = - std::get_if(&list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto* return_value = + std::get_if(&list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoNullableUint8List( const std::vector* a_list_arg, std::function*)>&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableUint8List", - &GetCodec()); + "echoNullableUint8List"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_list_arg ? EncodableValue(*a_list_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto* return_value = - std::get_if>(&list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto* return_value = + std::get_if>(&list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoNullableList( const EncodableList* a_list_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableList", - &GetCodec()); + "echoNullableList"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_list_arg ? EncodableValue(*a_list_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto* return_value = - std::get_if(&list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto* return_value = + std::get_if(&list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoNullableMap( const EncodableMap* a_map_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableMap", - &GetCodec()); + "echoNullableMap"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ a_map_arg ? EncodableValue(*a_map_arg) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto* return_value = - std::get_if(&list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto* return_value = + std::get_if(&list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoNullableEnum( const AnEnum* an_enum_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoNullableEnum", - &GetCodec()); + "echoNullableEnum"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ an_enum_arg ? EncodableValue((int)(*an_enum_arg)) : EncodableValue(), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), + channel->Send(encoded_api_arguments, [channel_name, + on_success = std::move(on_success), on_error = std::move(on_error)]( const uint8_t* reply, size_t reply_size) { @@ -4454,9 +4441,7 @@ void FlutterIntegrationCoreApi::EchoNullableEnum( on_success(return_value); } } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); + on_error(CreateConnectionError(channel_name)); } }); } @@ -4464,74 +4449,72 @@ void FlutterIntegrationCoreApi::EchoNullableEnum( void FlutterIntegrationCoreApi::NoopAsync( std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "noopAsync", - &GetCodec()); + "noopAsync"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - on_success(); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + on_success(); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterIntegrationCoreApi::EchoAsyncString( const std::string& a_string_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi." - "echoAsyncString", - &GetCodec()); + "echoAsyncString"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_string_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = - std::get(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = + std::get(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } /// The codec used by HostTrivialApi. @@ -4714,77 +4697,75 @@ void FlutterSmallApi::EchoWrappedList( const TestMessage& msg_arg, std::function&& on_success, std::function&& on_error) { - auto channel = std::make_unique>( - binary_messenger_, + const std::string channel_name = "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi." - "echoWrappedList", - &GetCodec()); + "echoWrappedList"; + auto channel = std::make_unique>( + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ CustomEncodableValue(msg_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = std::any_cast( - std::get(list_return_value->at(0))); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = std::any_cast( + std::get(list_return_value->at(0))); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } void FlutterSmallApi::EchoString( const std::string& a_string_arg, std::function&& on_success, std::function&& on_error) { + const std::string channel_name = + "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString"; auto channel = std::make_unique>( - binary_messenger_, - "dev.flutter.pigeon.pigeon_integration_tests.FlutterSmallApi.echoString", - &GetCodec()); + binary_messenger_, channel_name, &GetCodec()); EncodableValue encoded_api_arguments = EncodableValue(EncodableList{ EncodableValue(a_string_arg), }); - channel->Send(encoded_api_arguments, [on_success = std::move(on_success), - on_error = std::move(on_error)]( - const uint8_t* reply, - size_t reply_size) { - std::unique_ptr response = - GetCodec().DecodeMessage(reply, reply_size); - const auto& encodable_return_value = *response; - const auto* list_return_value = - std::get_if(&encodable_return_value); - if (list_return_value) { - if (list_return_value->size() > 1) { - on_error(FlutterError(std::get(list_return_value->at(0)), - std::get(list_return_value->at(1)), - list_return_value->at(2))); - } else { - const auto& return_value = - std::get(list_return_value->at(0)); - on_success(return_value); - } - } else { - on_error(FlutterError("channel-error", - "Unable to establish connection on channel.", - EncodableValue(""))); - } - }); + channel->Send( + encoded_api_arguments, [channel_name, on_success = std::move(on_success), + on_error = std::move(on_error)]( + const uint8_t* reply, size_t reply_size) { + std::unique_ptr response = + GetCodec().DecodeMessage(reply, reply_size); + const auto& encodable_return_value = *response; + const auto* list_return_value = + std::get_if(&encodable_return_value); + if (list_return_value) { + if (list_return_value->size() > 1) { + on_error( + FlutterError(std::get(list_return_value->at(0)), + std::get(list_return_value->at(1)), + list_return_value->at(2))); + } else { + const auto& return_value = + std::get(list_return_value->at(0)); + on_success(return_value); + } + } else { + on_error(CreateConnectionError(channel_name)); + } + }); } } // namespace core_tests_pigeontest diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index b4b0240bf9f1..6a88b0a0c710 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: 13.0.0 # This must match the version in lib/generator_tools.dart +version: 13.1.0 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.19.0 <4.0.0" diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index d7e3dbdaab13..be426c1c395e 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -1991,4 +1991,51 @@ void main() { // changes to lambda capture. expect(code, contains('[reply](')); }); + + test('connection error contains channel name', () { + final Root root = Root( + apis: [ + Api( + name: 'Api', + location: ApiLocation.flutter, + methods: [ + Method( + name: 'method', + returnType: const TypeDeclaration.voidDeclaration(), + arguments: [ + NamedType( + name: 'field', + type: const TypeDeclaration( + baseName: 'int', + isNullable: true, + ), + ), + ], + ) + ], + ) + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const CppGenerator generator = CppGenerator(); + final OutputFileOptions generatorOptions = + OutputFileOptions( + fileType: FileType.source, + languageOptions: const CppOptions(), + ); + generator.generate( + generatorOptions, + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains( + '"Unable to establish connection on channel: \'" + channel_name + "\'."')); + expect(code, contains('on_error(CreateConnectionError(channel_name));')); + }); } diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 5ca7ef73e4b2..fdf9c1d1b874 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1613,4 +1613,31 @@ name: foobar contains( 'final Enum? arg_anEnum = args[0] == null ? null : Enum.values[args[0]! as int]')); }); + + test('connection error contains channel name', () { + final Root root = Root(apis: [ + Api(name: 'Api', location: ApiLocation.host, methods: [ + Method( + name: 'method', + arguments: [], + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), + ) + ]) + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + const DartGenerator generator = DartGenerator(); + generator.generate( + const DartOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect(code, contains('throw _createConnectionError(channelName);')); + expect( + code, + contains( + '\'Unable to establish connection on channel: "\$channelName".\'')); + }); } diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index 4a36acec6dbc..15abd016a68b 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -41,12 +41,6 @@ void main() { expect(code, contains('public static final class Foobar')); expect(code, contains('public static final class Builder')); expect(code, contains('private @Nullable Long field1;')); - expect( - code, - contains(RegExp( - r'@NonNull\s*protected static ArrayList wrapError\(@NonNull Throwable exception\)'))); - expect(code, isNot(contains('ArrayList '))); - expect(code, isNot(contains('ArrayList<>'))); }); test('gen one enum', () { @@ -170,6 +164,12 @@ void main() { code, contains( 'protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value)')); + expect( + code, + contains(RegExp( + r'@NonNull\s*protected static ArrayList wrapError\(@NonNull Throwable exception\)'))); + expect(code, isNot(contains('ArrayList '))); + expect(code, isNot(contains('ArrayList<>'))); }); test('all the simple datatypes header', () { @@ -1558,10 +1558,48 @@ void main() { ); final String code = sink.toString(); expect(code, contains('class FlutterError')); - expect(code, contains('if (exception instanceof FlutterError)')); - expect(code, contains('FlutterError error = (FlutterError) exception;')); - expect(code, contains('errorList.add(error.code);')); - expect(code, contains('errorList.add(error.getMessage());')); - expect(code, contains('errorList.add(error.details);')); + }); + + test('connection error contains channel name', () { + final Root root = Root( + apis: [ + Api( + name: 'Api', + location: ApiLocation.flutter, + methods: [ + Method( + name: 'method', + returnType: const TypeDeclaration.voidDeclaration(), + arguments: [ + NamedType( + name: 'field', + type: const TypeDeclaration( + baseName: 'int', + isNullable: true, + ), + ), + ], + ) + ], + ) + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const JavaGenerator generator = JavaGenerator(); + const JavaOptions javaOptions = JavaOptions(className: 'Messages'); + generator.generate( + javaOptions, + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect(code, contains('createConnectionError(channelName)')); + expect( + code, + contains( + 'return new FlutterError("channel-error", "Unable to establish connection on channel: " + channelName + ".", "");')); }); } diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index 596b25b51fa0..19527e8f2a6f 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -1540,4 +1540,50 @@ void main() { expect(code, contains('exception.message,')); expect(code, contains('exception.details')); }); + + test('connection error contains channel name', () { + final Root root = Root( + apis: [ + Api( + name: 'Api', + location: ApiLocation.flutter, + methods: [ + Method( + name: 'method', + returnType: const TypeDeclaration.voidDeclaration(), + arguments: [ + NamedType( + name: 'field', + type: const TypeDeclaration( + baseName: 'int', + isNullable: true, + ), + ), + ], + ) + ], + ) + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const KotlinOptions kotlinOptions = KotlinOptions(); + const KotlinGenerator generator = KotlinGenerator(); + generator.generate( + kotlinOptions, + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains( + 'return FlutterError("channel-error", "Unable to establish connection on channel: \'\$channelName\'.", "")')); + expect( + code, + contains( + 'callback(Result.failure(createConnectionError(channelName)));')); + }); } diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index d55bd657498e..ef1d91f1f70d 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -2719,4 +2719,51 @@ void main() { final String code = sink.toString(); expect(code, contains(' : FlutterStandardReader')); }); + + test('connection error contains channel name', () { + final Root root = Root( + apis: [ + Api( + name: 'Api', + location: ApiLocation.flutter, + methods: [ + Method( + name: 'method', + returnType: const TypeDeclaration.voidDeclaration(), + arguments: [ + NamedType( + name: 'field', + type: const TypeDeclaration( + baseName: 'int', + isNullable: true, + ), + ), + ], + ) + ], + ) + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const ObjcGenerator generator = ObjcGenerator(); + final OutputFileOptions generatorOptions = + OutputFileOptions( + fileType: FileType.source, + languageOptions: const ObjcOptions(), + ); + generator.generate( + generatorOptions, + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains( + 'return [FlutterError errorWithCode:@"channel-error" message:[NSString stringWithFormat:@"%@/%@/%@", @"Unable to establish connection on channel: \'", channelName, @"\'."] details:@""]')); + expect(code, contains('completion(createConnectionError(channelName))')); + }); } diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index 9453b8577f9a..622b51b6ec3b 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -1436,4 +1436,50 @@ void main() { final String code = sink.toString(); expect(code, contains('func removeAll()')); }); + + test('connection error contains channel name', () { + final Root root = Root( + apis: [ + Api( + name: 'Api', + location: ApiLocation.flutter, + methods: [ + Method( + name: 'method', + returnType: const TypeDeclaration.voidDeclaration(), + arguments: [ + NamedType( + name: 'field', + type: const TypeDeclaration( + baseName: 'int', + isNullable: true, + ), + ), + ], + ) + ], + ) + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const SwiftOptions kotlinOptions = SwiftOptions(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + kotlinOptions, + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + expect( + code, + contains( + 'completion(.failure(createConnectionError(withChannelName:channelName)))')); + expect( + code, + contains( + 'return FlutterError(code: "channel-error", message: "Unable to establish connection on channel: \'\\(channelName)\'.", details: "")')); + }); }