Skip to content

Commit 30d331e

Browse files
committed
fix(generator-common): retry broken contributors
1 parent 23cf8be commit 30d331e

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

generator/common/src/main/kotlin/me/kcra/takenaka/generator/common/provider/impl/ResolvingMappingProvider.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class ResolvingMappingProvider @Deprecated(
138138
if (contributor is OutputContainer<*>) {
139139
contributor.forEach { output ->
140140
launch(Dispatchers.Default + CoroutineName("resolve-coro")) {
141-
output.resolve()
141+
runCatching { output.resolve() }
142+
.onFailure { e -> logger.error(e) { "Failed to pre-fetch output $output" } }
142143
}
143144
}
144145
}
@@ -147,14 +148,14 @@ class ResolvingMappingProvider @Deprecated(
147148

148149
val treeResult = runCatching {
149150
buildMappingTree {
150-
contributor(contributors)
151+
contributor(contributors.map { RetryingContributor(it, 5) })
151152

152153
interceptors += mappingConfig.interceptors
153154
}
154155
}
155156

156-
val tree = treeResult.getOrElse { exc ->
157-
throw ResolveException("Failed to create mapping tree for version ${workspace.version}", exc)
157+
val tree = treeResult.getOrElse { e ->
158+
throw ResolveException("Failed to create mapping tree for version ${workspace.version.id}", e)
158159
}
159160
if (analyzer != null) {
160161
val time = measureTimeMillis { analyzer.accept(tree) }
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of takenaka, licensed under the Apache License, Version 2.0 (the "License").
3+
*
4+
* Copyright (c) 2023-2024 Matous Kucera
5+
*
6+
* You may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package me.kcra.takenaka.generator.common.provider.impl
19+
20+
import io.github.oshai.kotlinlogging.KotlinLogging
21+
import me.kcra.takenaka.core.mapping.MappingContributor
22+
import net.fabricmc.mappingio.MappingVisitor
23+
24+
private val logger = KotlinLogging.logger {}
25+
26+
/**
27+
* A wrapping mapping contributor that retries for [retries] times, if an exception is thrown.
28+
*
29+
* @property contributor the wrapped contributor
30+
* @property retries the number of retries after which we should give up
31+
* @property name the contributor name (used for diagnostics)
32+
* @author Matouš Kučera
33+
*/
34+
internal class RetryingContributor(
35+
val contributor: MappingContributor,
36+
val retries: Int,
37+
val name: String = contributor.javaClass.simpleName
38+
) : MappingContributor {
39+
override val targetNamespace by contributor::targetNamespace
40+
41+
override fun accept(visitor: MappingVisitor) {
42+
repeat(retries - 1) { i ->
43+
try {
44+
return contributor.accept(visitor)
45+
} catch (e: Throwable) {
46+
logger.error(e) { "Mapping contributor '$name' threw exception, try ${i + 1}/$retries" }
47+
}
48+
}
49+
50+
return contributor.accept(visitor)
51+
}
52+
}

0 commit comments

Comments
 (0)