awslabs / aws-lambda-dart-runtime

A Dart runtime for AWS Lambda
https://awslabs.github.io/aws-lambda-dart-runtime/
Apache License 2.0
146 stars 30 forks source link

Posting invocation error fails some times #7

Closed Schwusch closed 4 years ago

Schwusch commented 4 years ago

When the runtime tries posting an invocation error I got this

Unhandled exception:
type '_InternalLinkedHashMap<String, String>' is not a subtype of type 'String'
#0      Client.postInvocationError (package:aws_lambda_dart_runtime/client/client.dart:156)
#1      _RootZone.runUnary (dart:async/zone.dart:1381)
#2      _FutureListener.handleValue (dart:async/future_impl.dart:139)
#3      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680)
#4      Future._propagateToListeners (dart:async/future_impl.dart:709)
#5      Future._completeWithValue (dart:async/future_impl.dart:524)
#6      Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554)
#7      _microtaskLoop (dart:async/schedule_microtask.dart:43)
#8      _startMicrotaskLoop (dart:async/schedule_microtask.dart:52)
#9      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:393)
#10     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418)
#11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174)

When I changed this line: https://github.com/awslabs/aws-lambda-dart-runtime/blob/2e61c448f4472f42bd605c5fb03f065e9edfe50c/lib/client/client.dart#L156 to this:

request.add(utf8.encode(jsonEncode(err.error)));

It got past that line. If the error object has a toJson() (which is not guaranteed), customary in Dart is to return Map<String, dynamic>, which is not what utf8.encode() expects. I think a more stable solution is to simply call toString() on the error object.