From 9d0a2bc3ce73971d1f9b9fc6b56c07cc9e80a7e9 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 25 Jun 2023 17:11:59 +0200 Subject: [PATCH 1/2] Client - Documented that `initEvents()` may throw an `EventyException` ErrorType - Added new member `INTERNAL_FAILURE` which could occur from errors with `Eventy` when setting up the signal handlers and event types --- source/birchwood/client/exceptions.d | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/birchwood/client/exceptions.d b/source/birchwood/client/exceptions.d index 7258c38..5564f3d 100644 --- a/source/birchwood/client/exceptions.d +++ b/source/birchwood/client/exceptions.d @@ -15,6 +15,13 @@ import std.conv : to; */ public enum ErrorType { + /** + * This could occur from errors with `Eventy` + * when setting up the signal handlers and + * event types + */ + INTERNAL_FAILURE, + /** * If the provided connection information * is invalid, such as incorrect hostname, From 42f63b9e0e5852d4029c25519bd6b2e091339f0c Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 25 Jun 2023 17:12:24 +0200 Subject: [PATCH 2/2] Client - We now catch `EventyException` when calling `initEvents()` from within `connect()` and throw a `BirchwoodException` --- source/birchwood/client/client.d | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 55e7453..9921431 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -10,7 +10,7 @@ import std.container.slist : SList; import core.sync.mutex : Mutex; import core.thread : Thread, dur; import std.string; -import eventy : EventyEvent = Event, Engine, EventType, Signal; +import eventy : EventyEvent = Event, Engine, EventType, Signal, EventyException; import birchwood.config; import birchwood.client.exceptions : BirchwoodException, ErrorType; import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText; @@ -649,8 +649,12 @@ public class Client : Thread } /** - * Initialize the event handlers - */ + * Initialize the event handlers + * + * Throws: + * `EventyException` on error registering + * the signals and event types + */ private void initEvents() { /* TODO: For now we just register one signal type for all messages */ @@ -775,7 +779,8 @@ public class Client : Thread * Connects to the server * * Throws: - * BirchwoodException if there is an error connecting + * `BirchwoodException` if there is an error connecting + * or something failed internally */ public void connect() { @@ -820,6 +825,10 @@ public class Client : Thread { throw new BirchwoodException(ErrorType.CONNECT_ERROR); } + catch(EventyException e) + { + throw new BirchwoodException(ErrorType.INTERNAL_FAILURE, e.toString()); + } } // TODO: Do actual liveliness check here else