mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
refactor: use Zod validation for executionError getter
- Export zExecutionErrorWsMessage schema from apiSchema - Use safeParse instead of type casts in TaskItemImpl.executionError - Simplify errorMessage getter to delegate to executionError 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ const zExecutionInterruptedWsMessage = zExecutionWsMessageBase.extend({
|
|||||||
node_type: zNodeType,
|
node_type: zNodeType,
|
||||||
executed: z.array(zNodeId)
|
executed: z.array(zNodeId)
|
||||||
})
|
})
|
||||||
const zExecutionErrorWsMessage = zExecutionWsMessageBase.extend({
|
export const zExecutionErrorWsMessage = zExecutionWsMessageBase.extend({
|
||||||
node_id: zNodeId,
|
node_id: zNodeId,
|
||||||
node_type: zNodeType,
|
node_type: zNodeType,
|
||||||
executed: z.array(zNodeId),
|
executed: z.array(zNodeId),
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import type {
|
|||||||
ComfyWorkflowJSON,
|
ComfyWorkflowJSON,
|
||||||
NodeId
|
NodeId
|
||||||
} from '@/platform/workflow/validation/schemas/workflowSchema'
|
} from '@/platform/workflow/validation/schemas/workflowSchema'
|
||||||
|
import { zExecutionErrorWsMessage } from '@/schemas/apiSchema'
|
||||||
import type {
|
import type {
|
||||||
ExecutionErrorWsMessage,
|
ExecutionErrorWsMessage,
|
||||||
HistoryTaskItem,
|
HistoryTaskItem,
|
||||||
@@ -324,35 +325,26 @@ export class TaskItemImpl {
|
|||||||
/**
|
/**
|
||||||
* Extracts the execution error message from status messages.
|
* Extracts the execution error message from status messages.
|
||||||
* Used by error reporting UI components.
|
* Used by error reporting UI components.
|
||||||
*
|
|
||||||
* Note: The type cast is required because `messages` is typed as
|
|
||||||
* `Array<[string, unknown]>` - TypeScript cannot narrow the second tuple
|
|
||||||
* element's type based on a runtime string check for 'execution_error'.
|
|
||||||
*/
|
*/
|
||||||
get errorMessage(): string | undefined {
|
get errorMessage(): string | undefined {
|
||||||
const messages = this.status?.messages
|
return this.executionError?.exception_message
|
||||||
if (!Array.isArray(messages) || !messages.length) return undefined
|
|
||||||
const record = messages.find(
|
|
||||||
(entry: unknown) => Array.isArray(entry) && entry[0] === 'execution_error'
|
|
||||||
) as [string, { exception_message?: string }?] | undefined
|
|
||||||
return record?.[1]?.exception_message
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the full execution error from status messages.
|
* Extracts the full execution error from status messages.
|
||||||
* Returns the ExecutionErrorWsMessage for detailed error dialogs.
|
* Returns the ExecutionErrorWsMessage for detailed error dialogs.
|
||||||
*
|
* Uses Zod validation to ensure type safety.
|
||||||
* Note: The type cast is required because `messages` is typed as
|
|
||||||
* `Array<[string, unknown]>` - TypeScript cannot narrow the second tuple
|
|
||||||
* element's type based on a runtime string check for 'execution_error'.
|
|
||||||
*/
|
*/
|
||||||
get executionError(): ExecutionErrorWsMessage | undefined {
|
get executionError(): ExecutionErrorWsMessage | undefined {
|
||||||
const messages = this.status?.messages
|
const messages = this.status?.messages
|
||||||
if (!Array.isArray(messages) || !messages.length) return undefined
|
if (!Array.isArray(messages) || !messages.length) return undefined
|
||||||
const record = messages.find(
|
for (const entry of messages) {
|
||||||
(entry: unknown) => Array.isArray(entry) && entry[0] === 'execution_error'
|
if (entry[0] === 'execution_error') {
|
||||||
) as [string, ExecutionErrorWsMessage?] | undefined
|
const parsed = zExecutionErrorWsMessage.safeParse(entry[1])
|
||||||
return record?.[1]
|
return parsed.success ? parsed.data : undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user