cli: prefer deepest stack error

This commit is contained in:
Bixilon 2022-05-18 15:51:21 +02:00
parent 6e8fdb78fe
commit dc2299368c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -35,13 +35,19 @@ abstract class CommandNode(
val pointer = reader.pointer
val stackSize = stack.size
var lastError: Throwable? = null
var highestStack = 0
for (child in children) {
try {
return executeChild(child, reader, stack)
} catch (error: Throwable) {
lastError = error
val size = stack.size
if (size >= highestStack) {
highestStack = size
lastError = error
}
}
reader.pointer = pointer
stack.reset(stackSize)
}
throw lastError ?: return