refactor(errors): унифицировал доменные ошибки и добавил failed-статус задач

This commit is contained in:
2026-05-18 14:52:33 +03:00
parent a1226a8803
commit f3f99aed5a
38 changed files with 498 additions and 112 deletions

View File

@@ -1,5 +1,7 @@
package com.github.nullptroma.wallenc.task.runtime
import com.github.nullptroma.wallenc.domain.errors.WallencException
import com.github.nullptroma.wallenc.domain.errors.toWallencException
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
import com.github.nullptroma.wallenc.domain.tasks.PipelineState
import com.github.nullptroma.wallenc.domain.tasks.PipelineTask
@@ -188,9 +190,13 @@ class TaskOrchestrator(
replaceTask(taskId) { it.copy(state = TaskRunState.Completed) }
} catch (_: CancellationException) {
replaceTask(taskId) { it.copy(state = TaskRunState.Cancelled) }
} catch (e: TaskFailedException) {
replaceTask(taskId) {
it.copy(state = TaskRunState.Failed(e.error))
}
} catch (e: Exception) {
replaceTask(taskId) {
it.copy(state = TaskRunState.Failed(e.message ?: e.toString()))
it.copy(state = TaskRunState.Failed(e.toWallencException()))
}
} finally {
cancelRequested.remove(taskId)
@@ -216,8 +222,14 @@ class TaskOrchestrator(
override fun log(level: TaskLogLevel, message: String) {
appendLog(level, message)
}
override fun fail(error: WallencException): Nothing {
throw TaskFailedException(error)
}
}
private class TaskFailedException(val error: WallencException) : RuntimeException()
companion object {
private const val MAX_LOG_LINES = 500
private const val FOREGROUND_DELAY_MS = 1_000L