1 /** 2 * Exception handling 3 */ 4 module birchwood.client.exceptions; 5 6 import std.conv : to; 7 8 /** 9 * The type of error to be used 10 * with BirchwoodException 11 * 12 * TODO: Make this STRING and associate a message with it 13 * but make it include the enum name and corresponding value 14 * when throwin an exception 15 */ 16 public enum ErrorType 17 { 18 /** 19 * This could occur from errors with `Eventy` 20 * when setting up the signal handlers and 21 * event types. It can also occur if `libsnooze` 22 * has an error which would occur when calling 23 * `ensure(Thread)` for the `Receiver` and `Sender` 24 * threads 25 */ 26 INTERNAL_FAILURE, 27 28 /** 29 * If the provided connection information 30 * is invalid, such as incorrect hostname, 31 * invalid nick 32 */ 33 INVALID_CONN_INFO, 34 35 /** 36 * If an attempt to call connect() is made 37 * when already connected 38 */ 39 ALREADY_CONNECTED, 40 41 /** 42 * If there is an erroring opening a connection 43 * to the endpoint server 44 */ 45 CONNECT_ERROR, 46 47 /** 48 * If invalid parameter information is provided 49 * to an IRC command method 50 */ 51 EMPTY_PARAMS, 52 53 /** 54 * If an invalid channel name is provided 55 */ 56 INVALID_CHANNEL_NAME, 57 58 /** 59 * If an invalid nickname is provided 60 */ 61 INVALID_NICK_NAME, 62 63 /** 64 * If illegal characters exist within the 65 * message 66 */ 67 ILLEGAL_CHARACTERS, 68 69 /** 70 * If the final encoded IRC message 71 * is too long to send to the server 72 */ 73 COMMAND_TOO_LONG, 74 75 /** 76 * If invalid parameters are passed 77 * to any of the text formatting functions 78 */ 79 INVALID_FORMATTING, 80 81 /** 82 * If a key-lookup in the ConnInfo failed 83 */ 84 DB_KEY_NOT_FOUND, 85 86 /** 87 * If the requested nickname (via /NICK) is 88 * too long 89 */ 90 NICKNAME_TOO_LONG 91 } 92 93 /** 94 * A runtime exception in the Birchwood library 95 */ 96 public class BirchwoodException : Exception 97 { 98 /** 99 * The specific type of error occurred 100 */ 101 private ErrorType errType; 102 103 /** 104 * Auxillary information 105 */ 106 private string auxInfo; 107 108 /** 109 * Constructs a new exception with the given sub-error type 110 * and infers the auxillary information based on said sub-error 111 * type 112 * 113 * Params: 114 * errType = the sub-error type 115 */ 116 this(ErrorType errType) 117 { 118 super("BirchwoodError("~to!(string)(errType)~")"~(auxInfo.length == 0 ? "" : " "~auxInfo)); 119 this.errType = errType; 120 } 121 122 /** 123 * Constructs a new exception with the given sub-error type 124 * and auxillary information 125 * 126 * Params: 127 * errType = the sub-error type 128 * auxInfo = the auxillary information 129 */ 130 this(ErrorType errType, string auxInfo) 131 { 132 this(errType); 133 this.auxInfo = auxInfo; 134 } 135 136 /** 137 * Retrieve the specific error which occurred 138 * 139 * Returns: the ErrorType of the error 140 */ 141 public ErrorType getType() 142 { 143 return errType; 144 } 145 }