From e054dacb3a7cad2e3f9535862b698bc5aa19ea08 Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Sun, 12 May 2024 08:26:26 +0400 Subject: [PATCH] chore: Improve error handling in SpinifyCommandMixin --- lib/src/spinify_impl.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/spinify_impl.dart b/lib/src/spinify_impl.dart index 0f45917..7106cf8 100644 --- a/lib/src/spinify_impl.dart +++ b/lib/src/spinify_impl.dart @@ -141,7 +141,12 @@ base mixin SpinifyCommandMixin on SpinifyBase { @override Future _onReply(SpinifyReply reply) async { - if (reply.id case int id when id > 0) _replies.remove(id)?.complete(reply); + assert(reply.id > -1, 'Reply ID should be greater or equal to 0'); + if (reply.id case int id when id > 0) { + final completer = _replies.remove(id); + assert(completer != null, 'Reply completer not found'); + completer?.complete(reply); + } await super._onReply(reply); }