@@ -31,7 +31,7 @@ import java.nio.charset.StandardCharsets.UTF_8
31
31
import java.nio.file.Files
32
32
import java.nio.file.Path
33
33
import java.nio.file.Paths
34
- import java.util.logging.Level
34
+ import java.util.logging.Level.SEVERE
35
35
import java.util.logging.Logger
36
36
37
37
/* *
@@ -150,7 +150,7 @@ class PersistentWorker(
150
150
private val io : WorkerIO ,
151
151
private val program : CommandLineProgram
152
152
) : Worker {
153
- val logger = Logger .getLogger(PersistentWorker ::class .java.canonicalName)
153
+ private val logger = Logger .getLogger(PersistentWorker ::class .java.canonicalName)
154
154
155
155
enum class Status {
156
156
OK , INTERRUPTED , ERROR
@@ -163,17 +163,15 @@ class PersistentWorker(
163
163
val (status, exit) = WorkingDirectoryContext .newContext()
164
164
.runCatching {
165
165
request.argumentsList
166
- ?.let {
167
- maybeExpand(it)
168
- }
166
+ ?.let { maybeExpand(it) }
169
167
.run {
170
168
Status .OK to program.apply (dir, maybeExpand(request.argumentsList))
171
169
}
172
170
}
173
171
.recover { e: Throwable ->
174
172
io.execution.write((e.message ? : e.toString()).toByteArray(UTF_8 ))
175
173
if (! e.wasInterrupted()) {
176
- logger.log(Level . SEVERE ,
174
+ logger.log(SEVERE ,
177
175
" ERROR: Worker threw uncaught exception" ,
178
176
e)
179
177
Status .ERROR to 1
@@ -183,10 +181,10 @@ class PersistentWorker(
183
181
}
184
182
.getOrThrow()
185
183
186
- val response = with ( WorkResponse .newBuilder()) {
184
+ val response = WorkResponse .newBuilder(). apply {
187
185
output = String (io.execution.toByteArray(), UTF_8 )
188
186
exitCode = exit
189
- setRequestId( request.requestId)
187
+ requestId = request.requestId
190
188
}.build()
191
189
192
190
// return the response
@@ -209,20 +207,18 @@ class InvocationWorker(
209
207
private val io : WorkerIO ,
210
208
private val program : CommandLineProgram
211
209
) : 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 ,
218
215
" ERROR: Worker threw uncaught exception with args: ${maybeExpand(args)} " ,
219
216
e)
220
- 1
221
- }.also {
217
+ return @recover 1 // return non-0 exitcode
218
+ }
219
+ .also {
220
+ // print execution log
222
221
println (String (io.execution.toByteArray(), UTF_8 ))
223
- }.getOrDefault( 0 )
224
- }
222
+ }
223
+ .getOrDefault( 0 )
225
224
}
226
-
227
-
228
-
0 commit comments