Unverified Commit 7cb2834a authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

StandardMethodCodec.decodeEnvelope should allow null error message (#71807)

* StandardMethodCodec.decodeEnvelope should allow null error message
parent 5dff7d29
......@@ -579,7 +579,7 @@ class StandardMethodCodec implements MethodCodec {
final dynamic errorDetails = messageCodec.readValue(buffer);
final String? errorStacktrace = (buffer.hasRemaining) ? messageCodec.readValue(buffer) as String : null;
if (errorCode is String && (errorMessage == null || errorMessage is String) && !buffer.hasRemaining)
throw PlatformException(code: errorCode, message: errorMessage as String, details: errorDetails, stacktrace: errorStacktrace);
throw PlatformException(code: errorCode, message: errorMessage as String?, details: errorDetails, stacktrace: errorStacktrace);
else
throw const FormatException('Invalid envelope');
}
......
......@@ -74,6 +74,25 @@ void main() {
throwsA(predicate((PlatformException e) =>
e is PlatformException && e.stacktrace == 'errorStacktrace')));
});
test('should allow null error message,', () {
final ByteData errorData = method.encodeErrorEnvelope(
code: 'errorCode',
message: null,
details: 'errorDetails',
);
expect(
() => method.decodeEnvelope(errorData),
throwsA(
predicate((PlatformException e) {
return e is PlatformException &&
e.code == 'errorCode' &&
e.message == null &&
e.details == 'errorDetails';
}),
),
);
});
});
group('Json method codec', () {
const JsonCodec json = JsonCodec();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment