summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/geb/exceptions
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-08-24 01:50:14 +0200
committer zaaarf <zaaarf@proton.me>2023-08-24 01:50:14 +0200
commitca13fffd0e356a4a0c73563ff90a145acb5d7706 (patch)
tree99b87027ece6858339d7da2d8e030d3977ee85e8 /src/main/java/ftbsc/geb/exceptions
parent17398e89db3b4c505a2a65130baf5cd28e20cc1c (diff)
feat: proper error handling
Diffstat (limited to 'src/main/java/ftbsc/geb/exceptions')
-rw-r--r--src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java52
-rw-r--r--src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java17
2 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java b/src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java
new file mode 100644
index 0000000..a15b4e5
--- /dev/null
+++ b/src/main/java/ftbsc/geb/exceptions/BadListenerArgumentsException.java
@@ -0,0 +1,52 @@
+package ftbsc.geb.exceptions;
+
+/**
+ * Thrown when there is something wrong with a listener method.
+ */
+public class BadListenerArgumentsException extends RuntimeException {
+
+ /**
+ * The constructor. It's not meant to be used as is, refer to the subclasses
+ * @param message the message to pass along to the superclass
+ */
+ protected BadListenerArgumentsException(String message) {
+ super(message);
+ }
+
+ /**
+ * Thrown when the number of arguments is off.
+ */
+ public static class Count extends BadListenerArgumentsException {
+
+ /**
+ * The public constructor.
+ * @param clazz the fully-qualified name of the parent class
+ * @param method the annotated listener method
+ * @param count the number of arguments found
+ */
+ public Count(String clazz, String method, int count) {
+ super(String.format(
+ "An error occurred while evaluating method %s::%s: found %d arguments, expected 1!",
+ clazz, method, count));
+ }
+ }
+
+ /**
+ * Thrown when the argument is of the wrong type.
+ */
+ public static class Type extends BadListenerArgumentsException {
+
+ /**
+ * The public constructor.
+ * @param clazz the fully-qualified name of the parent class
+ * @param method the annotated listener method
+ * @param parameterName the name of the parameter
+ */
+ public Type(String clazz, String method, String parameterName) {
+ super(String.format(
+ "The parameter %s of %s::%s does not implement the IEvent interface!",
+ parameterName, clazz, method
+ ));
+ }
+ }
+}
diff --git a/src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java b/src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java
new file mode 100644
index 0000000..e792729
--- /dev/null
+++ b/src/main/java/ftbsc/geb/exceptions/MissingInterfaceException.java
@@ -0,0 +1,17 @@
+package ftbsc.geb.exceptions;
+
+/**
+ * Thrown when a parent of a listener method does not implement the
+ * appropriate interface,
+ */
+public class MissingInterfaceException extends RuntimeException {
+
+ /**
+ * The public constructor.
+ * @param clazz the fully-qualified name of the parent class
+ * @param method the annotated listener method
+ */
+ public MissingInterfaceException(String clazz, String method) {
+ super(String.format("The parent of %s::%s does not implement the IListener interface!", clazz, method));
+ }
+}