OkaeriPoland / okaeri-configs

Simple Java/POJO config library written with love and Lombok
MIT License
83 stars 11 forks source link

Add friendly exception messages for errors #43

Open dasavick opened 1 year ago

dasavick commented 1 year ago

When the exception is raised, for example from the inside of the okaeri-configs converters, it should be possible to make the exception more user-friendly, at least for the most popular cases.

The user-friendly format of the new exceptions is yet to be determined. Suggestions are welcome.

For me, the end-game format would be inspired by the rust errors, but adding support for each backend may be tricky. I'm okay with making the message itself more friendly for all backends, and form only for YAML.

new_errors2

Example of the current unfriendly stacktrace:

[22:59:51 WARN]: eu.okaeri.configs.exception.OkaeriException: failed to #getValue for number
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.OkaeriConfig.update(OkaeriConfig.java:649)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.OkaeriConfig.load(OkaeriConfig.java:469)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.OkaeriConfig.load(OkaeriConfig.java:491)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.OkaeriConfig.load(OkaeriConfig.java:505)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.OkaeriConfig.load(OkaeriConfig.java:479)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.OkaeriConfig.load(OkaeriConfig.java:426)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//dev.bloedarend.spigottemplate.plugin.managers.ConfigManager$Companion.registerConfig(ConfigManager.kt:43)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//dev.bloedarend.spigottemplate.plugin.managers.ConfigManager$Companion.registerConfigs(ConfigManager.kt:26)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//dev.bloedarend.spigottemplate.plugin.Main.onEnable(Main.kt:25)
[22:59:51 WARN]:     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
[22:59:51 WARN]:     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370)
[22:59:51 WARN]:     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:542)
[22:59:51 WARN]:     at org.bukkit.craftbukkit.v1_19_R1.CraftServer.enablePlugin(CraftServer.java:565)
[22:59:51 WARN]:     at org.bukkit.craftbukkit.v1_19_R1.CraftServer.enablePlugins(CraftServer.java:479)
[22:59:51 WARN]:     at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:636)
[22:59:51 WARN]:     at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:422)
[22:59:51 WARN]:     at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:306)
[22:59:51 WARN]:     at net.minecraft.server.MinecraftServer.v(MinecraftServer.java:1100)
[22:59:51 WARN]:     at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:305)
[22:59:51 WARN]:     at java.base/java.lang.Thread.run(Thread.java:833)
[22:59:51 WARN]: Caused by: java.lang.ArithmeticException: Rounding necessary
[22:59:51 WARN]:     at java.base/java.math.BigDecimal.longValueExact(BigDecimal.java:3630)
[22:59:51 WARN]:     at java.base/java.math.BigDecimal.intValueExact(BigDecimal.java:3696)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.serdes.standard.StringToIntegerTransformer.transform(StringToIntegerTransformer.java:19)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.serdes.standard.StringToIntegerTransformer.transform(StringToIntegerTransformer.java:10)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.configurer.Configurer.resolveType(Configurer.java:399)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer.resolveType(YamlBukkitConfigurer.java:61)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.configurer.Configurer.resolveType(Configurer.java:334)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer.resolveType(YamlBukkitConfigurer.java:61)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.configurer.Configurer.getValue(Configurer.java:210)
[22:59:51 WARN]:     at SpigotTemplate-1.0.0.jar//eu.okaeri.configs.OkaeriConfig.update(OkaeriConfig.java:647)
[22:59:51 WARN]:     ... 19 more