Do not completely crash, store error and stacktrace when failing to decode reply.
This commit is contained in:
parent
0a5d99cd6f
commit
4de135284f
1 changed files with 10 additions and 1 deletions
|
@ -88,6 +88,9 @@ class PacketClient {
|
|||
}
|
||||
}
|
||||
|
||||
/// Tries to send a packet to the connected server
|
||||
///
|
||||
/// On success, returns either, the decoded [S2CResponse], or on error a S2CResponse containing an error and a stacktrace as [StringTag]
|
||||
Future<S2CResponse> send(IPacket packet) async {
|
||||
if (!connected) {
|
||||
return S2CResponse();
|
||||
|
@ -120,7 +123,13 @@ class PacketClient {
|
|||
await close();
|
||||
await startConnect(lastIP);
|
||||
S2CResponse reply = S2CResponse();
|
||||
reply.decodeTag(ct.get("result")!.asCompoundTag());
|
||||
try {
|
||||
reply.decodeTag(ct.get("result")!.asCompoundTag());
|
||||
} catch (E, stack) {
|
||||
reply.contents = CompoundTag(); // This is essentially a null response
|
||||
reply.contents.put("error", StringTag.valueOf(E.toString()));
|
||||
reply.contents.put("stacktrace", StringTag.valueOf(stack.toString()));
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue