From 06c348cf50bd717059e8e8e95b7a67451e27b586 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Mon, 21 Feb 2022 15:47:37 +0100 Subject: [PATCH] Avoid RPC getting "stuck" on responses that are not valid JSON. --- lib/desktop/rpc.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/desktop/rpc.dart b/lib/desktop/rpc.dart index a42f4d83..d487cd67 100644 --- a/lib/desktop/rpc.dart +++ b/lib/desktop/rpc.dart @@ -60,7 +60,14 @@ class RpcSession { : _responses = StreamQueue(_process.stdout .transform(const Utf8Decoder()) .transform(const LineSplitter()) - .map((event) => RpcResponse.fromJson(jsonDecode(event)))) { + .map((event) { + try { + return RpcResponse.fromJson(jsonDecode(event)); + } catch (e) { + _log.severe('Response was not valid JSON', event); + return RpcResponse.error('invalid-response', e.toString(), {}); + } + })) { _process.stderr .transform(const Utf8Decoder()) .transform(const LineSplitter())