mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Better compilation error reporting.
This commit is contained in:
parent
54fe92fee8
commit
475bdfffdb
1 changed files with 11 additions and 4 deletions
|
@ -181,19 +181,26 @@ class KotlinCompiler @Inject constructor(
|
||||||
throw UnsupportedOperationException("not implemented")
|
throw UnsupportedOperationException("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CompilerMessageLocation.dump(s: String) = "$lineContent\n$path:$line:$column $s"
|
fun dump(location: CompilerMessageLocation?, s: String) =
|
||||||
|
if (location != null && location.lineContent != null) {
|
||||||
|
with(location) {
|
||||||
|
"$lineContent\n$path:$line:$column $s"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
override fun report(severity: CompilerMessageSeverity,
|
override fun report(severity: CompilerMessageSeverity,
|
||||||
message: String, location: CompilerMessageLocation) {
|
message: String, location: CompilerMessageLocation) {
|
||||||
if (severity.isError) {
|
if (severity.isError) {
|
||||||
"Couldn't compile file: ${location.dump(message)}".let { fullMessage ->
|
"Couldn't compile file: ${dump(location, message)}".let { fullMessage ->
|
||||||
System.err.println(fullMessage)
|
System.err.println(fullMessage)
|
||||||
throw KobaltException(fullMessage)
|
throw KobaltException(fullMessage)
|
||||||
}
|
}
|
||||||
} else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) {
|
} else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) {
|
||||||
warn(location.dump(message))
|
warn(dump(location, message))
|
||||||
} else if (severity == CompilerMessageSeverity.INFO && KobaltLogger.LOG_LEVEL >= 2) {
|
} else if (severity == CompilerMessageSeverity.INFO && KobaltLogger.LOG_LEVEL >= 2) {
|
||||||
logk(2, location.dump(message))
|
logk(2, dump(location, message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue