Better mod loading error messages

This commit is contained in:
Yair Morgenstern
2022-02-06 15:05:44 +02:00
parent 5e29b1321b
commit e466db397c
2 changed files with 8 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package com.unciv
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.utils.Json
import com.unciv.logic.UncivShowableException
class JsonParser {
@ -11,7 +12,11 @@ class JsonParser {
fun <T> getFromJson(tClass: Class<T>, filePath: String): T = getFromJson(tClass, Gdx.files.internal(filePath))
fun <T> getFromJson(tClass: Class<T>, file: FileHandle): T {
val jsonText = file.readString(Charsets.UTF_8.name())
return json.fromJson(tClass, jsonText)
try{
val jsonText = file.readString(Charsets.UTF_8.name())
return json.fromJson(tClass, jsonText)
} catch (exception:Exception){
throw Exception("Could not parse json of file ${file.name()}", exception)
}
}
}

View File

@ -764,7 +764,7 @@ object RulesetCache : HashMap<String,Ruleset>() {
if (printOutput) {
println("Exception loading mod '${modFolder.name()}':")
println(" ${ex.localizedMessage}")
println(" (Source file ${ex.stackTrace[0].fileName} line ${ex.stackTrace[0].lineNumber})")
println(" ${ex.cause?.localizedMessage}")
}
}
}