diff --git a/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java b/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java index 99a9fba..57213ee 100644 --- a/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java +++ b/src/main/java/it/fulminazzo/yamlparser/configuration/IConfiguration.java @@ -1067,15 +1067,19 @@ default String getCurrentPath() { * @param e the e */ default void throwException(String path, Object object, Throwable e) { - if (e.getCause() != null && (e instanceof RuntimeException || e instanceof InvocationTargetException)) - e = e.getCause(); path = path == null ? "null" : path; String currentPath = getCurrentPath(); if (currentPath != null && !currentPath.isEmpty()) path = currentPath + "." + path; - String message = e.getMessage(); - if (e instanceof YAMLException) message = e.getMessage(); - else message = e.getClass().getSimpleName() + " " + message; - throw new YAMLException(path, object, message); + + if (e instanceof YAMLException) { + YAMLException yamlException = (YAMLException) e; + yamlException.setPath(path); + throw yamlException; + } + + if (e.getCause() != null && (e instanceof RuntimeException || e instanceof InvocationTargetException)) + e = e.getCause(); + throw new YAMLException(path, object, e.getClass().getSimpleName() + " " + e.getMessage()); } /** diff --git a/src/main/java/it/fulminazzo/yamlparser/exceptions/YAMLException.java b/src/main/java/it/fulminazzo/yamlparser/exceptions/YAMLException.java index f9eb937..94637f3 100644 --- a/src/main/java/it/fulminazzo/yamlparser/exceptions/YAMLException.java +++ b/src/main/java/it/fulminazzo/yamlparser/exceptions/YAMLException.java @@ -2,6 +2,7 @@ import it.fulminazzo.yamlparser.logging.LogMessage; import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,8 +11,9 @@ * while working with IConfiguration instances. */ @Getter +@Setter public class YAMLException extends RuntimeException { - private final @NotNull String path; + private @NotNull String path; private final @NotNull String name; private final @Nullable Object object;