StandardMethodCodec.decodeEnvelope should allow null error message (#71807)
* StandardMethodCodec.decodeEnvelope should allow null error message
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user