#1497 Show specific message for invalid YAML files (#1506)

* #1497 Throw dedicated exception for invalid YAML files and handle it on startup
- Wrap SnakeYAML exceptions when loading config.yml and commands.yml on startup into own exception type
- Handle exception type on startup with specific error message

* #1497 Fix inaccurate JavaDoc comment
This commit is contained in:
ljacqu
2018-02-23 23:31:22 +01:00
committed by GitHub
parent 7864bb06ac
commit 329657bd5f
10 changed files with 216 additions and 5 deletions
@@ -0,0 +1,36 @@
package fr.xephi.authme.util;
import com.google.common.collect.Sets;
import java.util.Set;
/**
* Utilities for exceptions.
*/
public final class ExceptionUtils {
private ExceptionUtils() {
}
/**
* Returns the first throwable of the given {@code wantedThrowableType} by visiting the provided
* throwable and its causes recursively.
*
* @param wantedThrowableType the throwable type to find
* @param throwable the throwable to start with
* @param <T> the desired throwable subtype
* @return the first throwable found of the given type, or null if none found
*/
public static <T extends Throwable> T findThrowableInCause(Class<T> wantedThrowableType, Throwable throwable) {
Set<Throwable> visitedObjects = Sets.newIdentityHashSet();
Throwable currentThrowable = throwable;
while (currentThrowable != null && !visitedObjects.contains(currentThrowable)) {
if (wantedThrowableType.isInstance(currentThrowable)) {
return wantedThrowableType.cast(currentThrowable);
}
visitedObjects.add(currentThrowable);
currentThrowable = currentThrowable.getCause();
}
return null;
}
}