Improve workflow error messaging
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { runTaskProcessor, type TaskExecutionOutcome } from '@/lib/server/task-processors';
|
||||
import { describeTaskFailure } from '@/lib/server/task-errors';
|
||||
import {
|
||||
completeTask,
|
||||
getTaskById,
|
||||
@@ -26,11 +27,9 @@ export async function runTaskWorkflow(taskId: string) {
|
||||
const outcome = await processTaskStep(refreshedTask);
|
||||
await completeTaskStep(task.id, outcome);
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error
|
||||
? error.message
|
||||
: 'Task failed unexpectedly';
|
||||
const latestTask = await loadTaskStep(task.id);
|
||||
await markTaskFailureStep(task.id, reason, latestTask);
|
||||
const failure = describeTaskFailure(latestTask ?? task, error);
|
||||
await markTaskFailureStep(task.id, failure, latestTask ?? task);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -63,10 +62,10 @@ async function completeTaskStep(taskId: string, outcome: TaskExecutionOutcome) {
|
||||
});
|
||||
}
|
||||
|
||||
async function markTaskFailureStep(taskId: string, reason: string, latestTask: Task | null) {
|
||||
async function markTaskFailureStep(taskId: string, failure: { summary: string; detail: string }, latestTask: Task) {
|
||||
'use step';
|
||||
await markTaskFailure(taskId, reason, 'failed', {
|
||||
detail: reason,
|
||||
context: latestTask?.stage_context ?? null
|
||||
await markTaskFailure(taskId, failure.detail, latestTask.stage === 'completed' ? 'failed' : latestTask.stage, {
|
||||
detail: failure.summary,
|
||||
context: latestTask.stage_context ?? null
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user