Right now ConfigurationNode#require throws NoSuchElementException, which is a RuntimeException and thus easily missed:
|
throw new NoSuchElementException("Node value was null when a non-null node was require()d"); |
This is distinct from all of the #get methods, which throw SerializationException (a configurate-specific checked exception) on failure. This also means that the exception is missing the additional details that are usually provided (path, expected type). As a result, I have to use this pattern:
ConfigurationNode threadsNode = node.node("threads");
Integer threads = threadsNode.get(Integer.class);
if (threads == null)
throw new SerializationException(threadsNode, Integer.class, "expected value but found null");
When node.node("threads").require(Integer.class) would be much more succinct if it threw the correct exception.
If this behavior is intended (or backwards compatibility is a concern), I still suggest introducing a new method with this behavior (something like requireChecked). Unless I'm missing something, I would be willing to make a pull request for this, as it looks like it should be pretty straightforward. I just need some direction on which way this should be solved.
This relates to #298
Right now
ConfigurationNode#requirethrowsNoSuchElementException, which is aRuntimeExceptionand thus easily missed:Configurate/core/src/main/java/org/spongepowered/configurate/ConfigurationNode.java
Line 410 in 033bdf8
This is distinct from all of the
#getmethods, which throwSerializationException(a configurate-specific checked exception) on failure. This also means that the exception is missing the additional details that are usually provided (path, expected type). As a result, I have to use this pattern:When
node.node("threads").require(Integer.class)would be much more succinct if it threw the correct exception.If this behavior is intended (or backwards compatibility is a concern), I still suggest introducing a new method with this behavior (something like
requireChecked). Unless I'm missing something, I would be willing to make a pull request for this, as it looks like it should be pretty straightforward. I just need some direction on which way this should be solved.This relates to #298