add error handling for loading of config.yml file #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Regarding the current code we have, it appears that when the config.yml file is initially loaded, it is done so within the reloadConfig() function. Upon examining the source code, it seems that this function does not explicitly throw any exceptions (see JavaPlugin.class) but somewhere inside it errors are handled.
I attempted to replicate and tweak its behavior in WeatherByLocation.java to gain more control However, my attempts were unsuccessful. Despite utilizing a broad try-catch-block such as using (Exception e), I continued to encounter exceptions such as InvalidConfigurationException and others, apparently frontrunning my own error handling logic. It appeared that Bukkit's error handling took precedence over my implementation, testing was done with a misaligned test config file.
During my search, I discovered that Bukkit employs a mechanism (although specifics remain unclear) where YamlConfiguration and its associated exceptions preemptively intercept mine during the loadConfiguration() process. To get around this I implemented a custom version of loadConfiguration(). This change gave us with greater control over handling the desired exceptions during the configuration loading process.
So as of now it is unclear which exceptions should be caught ( current have FileNotFoundException,IOException, ParserException, InvalidConfigurationException ). Any feedback in this regard would be greatly appreciated.
Additionally, it remains uncertain whether the server should terminate upon getting a bad configuration file - currently we are waiting 15 seconds then shutting down the server, otherwise we will run into the function that causes issues (reloadConfig() and or others) and we will see a bunch of exceptions).
The way that the shutdown is done is not pretty so i am looking for alternatives, but this is the best i have for now.
It is also probable that a custom class may be needed for the handling of config errors if we are to add more logic to the loadConfiguration() in order to avoid the WeatherByLocation.java being too busy with a slew of helper methods.