From b465585e91e9d975b42cf3cd9b6e9e942cff44dd Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Nov 2023 11:42:35 +0200 Subject: [PATCH] Client (unittest) - Added try-and-catch Client - Fixed error handling in `joinChannel(string)` --- source/dante/client.d | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/source/dante/client.d b/source/dante/client.d index 2ead19b..4fee30c 100644 --- a/source/dante/client.d +++ b/source/dante/client.d @@ -164,21 +164,20 @@ public class DanteClient writeln("Hallo"); writeln("Hallo"); - - // TODO: For absolute sanity we should check that // ... it actually decoded to the type we EXPECT // ... to be here (this would safeguard against // ... bad server implementations) // TODO: Make teh below a `mixin template` - ChannelMembership responseCommand = cast(ChannelMembership)response.getCommand(); + Command responseCommand = response.getCommand(); + ChannelMembership chanMemResp = cast(ChannelMembership)responseCommand; - if(responseCommand is null) + if(chanMemResp is null) { throw ProtocolException.expectedMessageKind(ChannelMembership.classinfo, responseCommand); } - if(responseCommand.wasGood()) + if(chanMemResp.wasGood()) { return; } @@ -334,9 +333,17 @@ unittest DanteClient client = new DanteClient(new UnixAddress("/tmp/renaissance.sock")); client.start(); - writeln("Joining channel #general..."); - client.joinChannel("#general"); - writeln("Joined"); + try + { + writeln("Joining channel #general..."); + client.joinChannel("#general"); + writeln("Joined"); + } + catch(DanteException e) + { + writeln("Got exception: ", e); + } + // string[] members = client.getMembers("#general");