Skip to content

Commit 3f4698a

Browse files
Corbin Smithcgruber
authored andcommitted
review cleanup
1 parent cc039db commit 3f4698a

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/main/kotlin/io/bazel/kotlin/builder/tasks/BazelWorker.kt

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import java.nio.charset.StandardCharsets.UTF_8
3131
import java.nio.file.Files
3232
import java.nio.file.Path
3333
import java.nio.file.Paths
34-
import java.util.logging.Level
34+
import java.util.logging.Level.SEVERE
3535
import java.util.logging.Logger
3636

3737
/**
@@ -150,7 +150,7 @@ class PersistentWorker(
150150
private val io: WorkerIO,
151151
private val program: CommandLineProgram
152152
) : Worker {
153-
val logger = Logger.getLogger(PersistentWorker::class.java.canonicalName)
153+
private val logger = Logger.getLogger(PersistentWorker::class.java.canonicalName)
154154

155155
enum class Status {
156156
OK, INTERRUPTED, ERROR
@@ -163,17 +163,15 @@ class PersistentWorker(
163163
val (status, exit) = WorkingDirectoryContext.newContext()
164164
.runCatching {
165165
request.argumentsList
166-
?.let {
167-
maybeExpand(it)
168-
}
166+
?.let { maybeExpand(it) }
169167
.run {
170168
Status.OK to program.apply(dir, maybeExpand(request.argumentsList))
171169
}
172170
}
173171
.recover { e: Throwable ->
174172
io.execution.write((e.message ?: e.toString()).toByteArray(UTF_8))
175173
if (!e.wasInterrupted()) {
176-
logger.log(Level.SEVERE,
174+
logger.log(SEVERE,
177175
"ERROR: Worker threw uncaught exception",
178176
e)
179177
Status.ERROR to 1
@@ -183,10 +181,10 @@ class PersistentWorker(
183181
}
184182
.getOrThrow()
185183

186-
val response = with(WorkResponse.newBuilder()) {
184+
val response = WorkResponse.newBuilder().apply {
187185
output = String(io.execution.toByteArray(), UTF_8)
188186
exitCode = exit
189-
setRequestId(request.requestId)
187+
requestId = request.requestId
190188
}.build()
191189

192190
// return the response
@@ -209,20 +207,18 @@ class InvocationWorker(
209207
private val io: WorkerIO,
210208
private val program: CommandLineProgram
211209
) : Worker {
212-
val logger: Logger = Logger.getLogger(InvocationWorker::class.java.canonicalName)
213-
override fun run(args: List<String>): Int {
214-
return WorkingDirectoryContext.newContext().runCatching {
215-
program.apply(dir, maybeExpand(args))
216-
}.recover { e ->
217-
logger.log(Level.SEVERE,
210+
private val logger: Logger = Logger.getLogger(InvocationWorker::class.java.canonicalName)
211+
override fun run(args: List<String>): Int = WorkingDirectoryContext.newContext()
212+
.runCatching { program.apply(dir, maybeExpand(args)) }
213+
.recover { e ->
214+
logger.log(SEVERE,
218215
"ERROR: Worker threw uncaught exception with args: ${maybeExpand(args)}",
219216
e)
220-
1
221-
}.also {
217+
return@recover 1 // return non-0 exitcode
218+
}
219+
.also {
220+
// print execution log
222221
println(String(io.execution.toByteArray(), UTF_8))
223-
}.getOrDefault(0)
224-
}
222+
}
223+
.getOrDefault(0)
225224
}
226-
227-
228-

0 commit comments

Comments
 (0)