*.gradle.kts: catch exceptions during GradleBuildRootManager initialization

^KT-39317 Fixed
This commit is contained in:
Natalia Selezneva
2020-06-29 22:46:38 +03:00
parent c7c7ffb0e0
commit 5ec110c33f
2 changed files with 12 additions and 3 deletions
@@ -346,10 +346,15 @@ class GradleBuildRootsManager(val project: Project) : GradleBuildRootsLocator(),
lastModifiedFiles: LastModifiedFiles = loadLastModifiedFiles(externalProjectPath) ?: LastModifiedFiles(),
dataProvider: (buildRoot: VirtualFile) -> GradleBuildRootData?
): Imported? {
val buildRoot = VfsUtil.findFile(Paths.get(externalProjectPath), true) ?: return null
val data = dataProvider(buildRoot) ?: return null
try {
val buildRoot = VfsUtil.findFile(Paths.get(externalProjectPath), true) ?: return null
val data = dataProvider(buildRoot) ?: return null
return Imported(externalProjectPath, data, lastModifiedFiles)
return Imported(externalProjectPath, data, lastModifiedFiles)
} catch (e: Exception) {
scriptingErrorLog("Cannot load script configurations from file attributes for $externalProjectPath", e)
return null
}
}
private fun add(newRoot: GradleBuildRoot) {
@@ -88,4 +88,8 @@ fun scriptingDebugLog(message: () -> String) {
fun scriptingInfoLog(message: String) {
logger.info("[KOTLIN_GRADLE_DSL] $message")
}
fun scriptingErrorLog(message: String, throwable: Throwable?) {
logger.error("[KOTLIN_GRADLE_DSL] $message", throwable)
}