From d144ec2ccde6e15e555f6b539a0d6d8c44c7179d Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sat, 27 May 2023 00:21:55 -0500 Subject: [PATCH] Show error list --- src/lib/ComfyGraphCanvas.ts | 42 +++- src/lib/components/ComfyApp.ts | 2 +- .../components/ComfyBoxWorkflowsView.svelte | 2 + src/lib/components/ComfyGraphErrorList.svelte | 228 ++++++++++++++++++ src/lib/components/ComfyGraphView.svelte | 7 +- src/lib/notify.ts | 2 +- 6 files changed, 277 insertions(+), 6 deletions(-) create mode 100644 src/lib/components/ComfyGraphErrorList.svelte diff --git a/src/lib/ComfyGraphCanvas.ts b/src/lib/ComfyGraphCanvas.ts index d66f47d..b63f9a5 100644 --- a/src/lib/ComfyGraphCanvas.ts +++ b/src/lib/ComfyGraphCanvas.ts @@ -22,6 +22,8 @@ export default class ComfyGraphCanvas extends LGraphCanvas { private _unsubscribe: Unsubscriber; isExportingSVG: boolean = false; activeErrors?: ComfyGraphErrors = null; + blinkError: ComfyGraphErrorLocation | null = null; + blinkErrorTime: number = 0; get comfyGraph(): ComfyGraph | null { return this.graph as ComfyGraph; @@ -96,8 +98,13 @@ export default class ComfyGraphCanvas extends LGraphCanvas { const isRunningNode = node.id == state.runningNodeID const nodeErrors = this.activeErrors?.errorsByID[node.id]; + if (this.blinkErrorTime > 0) { + this.blinkErrorTime -= this.graph.elapsed_time; + } + let color = null; let thickness = 1; + let blink = false; // if (this._selectedNodes.has(node.id)) { // color = "yellow"; // thickness = 5; @@ -111,6 +118,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas { else if (nodeErrors) { const hasExecutionError = nodeErrors.find(e => e.errorType === "execution"); if (hasExecutionError) { + blink = true; color = "#f0f"; } else { @@ -119,6 +127,14 @@ export default class ComfyGraphCanvas extends LGraphCanvas { thickness = 2 } + if (blink) { + if (nodeErrors && nodeErrors.includes(this.blinkError) && this.blinkErrorTime > 0) { + if ((Math.floor(this.blinkErrorTime / 2)) % 2 === 0) { + color = null; + } + } + } + if (color) { this.drawNodeOutline(node, ctx, size, mouseOver, fgColor, bgColor, color, thickness) } @@ -139,6 +155,11 @@ export default class ComfyGraphCanvas extends LGraphCanvas { ctx.strokeStyle = "red"; for (const errorLocation of errors) { if (errorLocation.input != null) { + if (errorLocation === this.blinkError && this.blinkErrorTime > 0) { + if ((Math.floor(this.blinkErrorTime / 2)) % 2 === 0) { + continue; + } + } const inputIndex = node.findInputSlotIndexByName(errorLocation.input.name) if (inputIndex !== -1) { let pos = node.getConnectionPos(true, inputIndex); @@ -607,17 +628,29 @@ export default class ComfyGraphCanvas extends LGraphCanvas { this.jumpToError(0); } - jumpToError(index: number) { + jumpToError(index: number | ComfyGraphErrorLocation) { if (this.activeErrors == null) { return; } - const error = this.activeErrors.errors[index] + let error; + if (typeof index === "number") { + error = this.activeErrors.errors[index] + } + else { + error = index; + } + if (error == null) { return; } - const node = this.graph.getNodeByIdRecursive(error.nodeID); + const rootGraph = this.graph.getRootGraph() + if (rootGraph == null) { + return + } + + const node = rootGraph.getNodeByIdRecursive(error.nodeID); if (node == null) { notify(`Couldn't find node '${error.comfyNodeType}' (${error.nodeID})`, { type: "warning" }) return @@ -637,5 +670,8 @@ export default class ComfyGraphCanvas extends LGraphCanvas { } this.centerOnNode(node); + + this.blinkError = error; + this.blinkErrorTime = 20; } } diff --git a/src/lib/components/ComfyApp.ts b/src/lib/components/ComfyApp.ts index d15cc2b..9f905be 100644 --- a/src/lib/components/ComfyApp.ts +++ b/src/lib/components/ComfyApp.ts @@ -309,7 +309,7 @@ export default class ComfyApp { if (errors && errors.length > 0) error = "Error(s) loading builtin templates:\n" + errors.join("\n"); - console.log(`Loaded {templates.length} builtin templates.`); + console.log(`Loaded ${templates.length} builtin templates.`); return [templates, error] }) diff --git a/src/lib/components/ComfyBoxWorkflowsView.svelte b/src/lib/components/ComfyBoxWorkflowsView.svelte index d3ed091..49b798e 100644 --- a/src/lib/components/ComfyBoxWorkflowsView.svelte +++ b/src/lib/components/ComfyBoxWorkflowsView.svelte @@ -240,6 +240,7 @@ } workflowState.setActiveWorkflow(app.lCanvas, workflow.id); + $uiState.activeError = promptIDWithError; const jumpToError = () => { app.resizeCanvas(); @@ -271,6 +272,7 @@ function hideError() { if (app?.lCanvas) { app.lCanvas.activeErrors = null; + app.lCanvas.blinkError = null; } } diff --git a/src/lib/components/ComfyGraphErrorList.svelte b/src/lib/components/ComfyGraphErrorList.svelte new file mode 100644 index 0000000..e435c18 --- /dev/null +++ b/src/lib/components/ComfyGraphErrorList.svelte @@ -0,0 +1,228 @@ + + +
+
+ +
+ {#each Object.entries(errors.errorsByID) as [nodeID, nodeErrors]} + {@const first = nodeErrors[0]} + {@const parent = getParentNode(first)} +
+
+ {first.comfyNodeType} + {#if parent} + ({parent.title}) + {/if} +
+
+ {#each nodeErrors as error} + {@const isExecutionError = error.errorType === "execution"} +
+
+
+ +
+ {error.message} + {#if error.exceptionType} + ({error.exceptionType}) + {:else if error.input} +
+ Input Name: {error.input.name} + {#if error.input.config} + Type: {getInputTypeName(error.input.config[0])} + {/if} +
+ {/if} +
+
+
+ {#if error.traceback} +
+ +
+
+ {#each error.traceback as line} +
{line}
+ {/each} +
+
+
+
+ {/if} +
+ {/each} +
+
+ {/each} +
+ + diff --git a/src/lib/components/ComfyGraphView.svelte b/src/lib/components/ComfyGraphView.svelte index f26ec8d..081f0fa 100644 --- a/src/lib/components/ComfyGraphView.svelte +++ b/src/lib/components/ComfyGraphView.svelte @@ -5,13 +5,15 @@ import interfaceState from "$lib/stores/interfaceState"; import workflowState from "$lib/stores/workflowState"; import uiState from '$lib/stores/uiState'; + import ComfyGraphErrorList from "$lib/components/ComfyGraphErrorList.svelte" export let app: ComfyApp; let canvas: HTMLCanvasElement; onMount(async () => { - if (app?.lCanvas && canvas) { + if (app?.lCanvas) { + canvas = app.lCanvas.canvas; app.lCanvas?.setCanvas(canvas) } }) @@ -40,6 +42,9 @@ {/if} + {#if $uiState.activeError && app?.lCanvas?.activeErrors != null} + + {/if}