Skip to content

[pigeon] Allow full control of PlatformException construction in all languages #120861

@cenumi

Description

@cenumi

Pigeon version 8.0.0

a table of supported language features would be nice

Swift generator use Int32 for dart int, while other languages use their 64bit number

  const Map<String, String> swiftTypeForDartTypeMap = <String, String>{
    ...
    'int': 'Int32',
    ...
  };

  const Map<String, String> javaTypeForDartTypeMap = <String, String>{
    ...
    'int': 'Long',
    ...
  };

  const Map<String, String> kotlinTypeForDartTypeMap = <String, String>{
    ...
    'int': 'Long',
    ...
  };

  final Map<String, String> cppTypeForDartTypeMap = <String, String>{
    ...
    'int': 'int64_t',
    ...
  };

Error wrapping is just confusing.

Objc support FlutterError [code,message,details]

static NSArray *wrapResult(id result, FlutterError *error) {
 if (error) {
    return @[
     terror.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null]
    ];
  }
  return @[ result ?: [NSNull null] ];
}

Swift support Error [type,toString,stackTrace] FlutterError [code,message,details].
Try catch block catch Error (throw), which FlutterError is not.

private func wrapError(_ error: Any) -> [Any?] {
  if let flutterError = error as? FlutterError {
    return [
      flutterError.code,
      flutterError.message,
      flutterError.details
    ]
  }
  return [
    "\(type(of: error))",
    "\(error)",
    "Stacktrace: \(Thread.callStackSymbols)"
  ]
}

Java support Throwable [toString,Type,stacktrace].
Try catch block catch Error | RuntimeException.

@NonNull
private static ArrayList<Object> wrapError(@NonNull Throwable exception) {
  ArrayList<Object> errorList = new ArrayList<Object>(3);
  errorList.add(exception.toString());
  errorList.add(exception.getClass().getSimpleName());
  errorList.add(
    "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
  return errorList;
}

Kotlin support Throwable [Type,toString,stackTrace].
Try catch block catch Error

private fun wrapError(exception: Throwable): List<Any> {
  return listOf<Any>(
    exception.javaClass.simpleName,
    exception.toString(),
    "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
  )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityfound in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions