Refactor script definition loading error handling

reenable logging of failures
suppress loading from failed contributors
This commit is contained in:
Ilya Chernikov
2019-03-19 11:27:30 +01:00
parent dd3ac74bd2
commit f2bddce4fd
2 changed files with 15 additions and 6 deletions
@@ -69,6 +69,8 @@ class ScriptDefinitionsManager(private val project: Project) : LazyScriptDefinit
private var definitionsByContributor = mutableMapOf<ScriptDefinitionContributor, List<KotlinScriptDefinition>>()
private var definitions: List<KotlinScriptDefinition>? = null
private val failedContributorsHashes = HashSet<Int>()
private val scriptDefinitionsCacheLock = ReentrantReadWriteLock()
private val scriptDefinitionsCache = SLRUMap<String, KotlinScriptDefinition>(10, 10)
@@ -195,13 +197,14 @@ class ScriptDefinitionsManager(private val project: Project) : LazyScriptDefinit
}
private fun ScriptDefinitionContributor.safeGetDefinitions(): List<KotlinScriptDefinition> {
return try {
getDefinitions()
if (!failedContributorsHashes.contains(this@safeGetDefinitions.hashCode())) try {
return getDefinitions()
} catch (t: Throwable) {
// TODO: review exception handling
// possibly log, see KT-19276
emptyList()
// reporting failed loading only once
LOG.error("[kts] cannot load script definitions using $this", t)
failedContributorsHashes.add(this@safeGetDefinitions.hashCode())
}
return emptyList()
}
companion object {