Improve workflow error messaging
This commit is contained in:
@@ -406,11 +406,13 @@ export async function markTaskFailure(
|
||||
export async function setTaskStatusFromWorkflow(
|
||||
taskId: string,
|
||||
status: TaskStatus,
|
||||
error?: string | null
|
||||
error?: string | null,
|
||||
detail?: string | null
|
||||
) {
|
||||
const isTerminal = status === 'completed' || status === 'failed';
|
||||
const nextStage = statusToStage(status);
|
||||
const nextError = status === 'failed' ? (error ?? 'Workflow run failed') : null;
|
||||
const nextDetail = nextStatusDetail(status, nextError, detail);
|
||||
|
||||
return await db.transaction(async (tx) => {
|
||||
const [current] = await tx
|
||||
@@ -426,7 +428,7 @@ export async function setTaskStatusFromWorkflow(
|
||||
const hasNoStateChange = current.status === status
|
||||
&& current.stage === nextStage
|
||||
&& (current.error ?? null) === nextError
|
||||
&& (current.stage_detail ?? null) === (nextStatusDetail(status, nextError) ?? null)
|
||||
&& (current.stage_detail ?? null) === (nextDetail ?? null)
|
||||
&& (current.stage_context ?? null) === null
|
||||
&& (isTerminal ? current.finished_at !== null : current.finished_at === null);
|
||||
|
||||
@@ -440,7 +442,7 @@ export async function setTaskStatusFromWorkflow(
|
||||
.set({
|
||||
status,
|
||||
stage: nextStage,
|
||||
stage_detail: nextStatusDetail(status, nextError),
|
||||
stage_detail: nextDetail,
|
||||
stage_context: null,
|
||||
error: nextError,
|
||||
updated_at: now,
|
||||
@@ -506,9 +508,9 @@ export async function updateTaskNotificationState(
|
||||
return row ? toTask(row) : null;
|
||||
}
|
||||
|
||||
function nextStatusDetail(status: TaskStatus, error?: string | null) {
|
||||
function nextStatusDetail(status: TaskStatus, error?: string | null, detail?: string | null) {
|
||||
if (status === 'failed') {
|
||||
return error ?? 'Workflow run failed';
|
||||
return detail ?? error ?? 'Workflow run failed';
|
||||
}
|
||||
|
||||
if (status === 'completed') {
|
||||
|
||||
Reference in New Issue
Block a user