@@ -235,6 +235,10 @@ export class CanvasStateApiModule extends CanvasModuleBase {
235
235
} ) : Promise < ImageDTO > => {
236
236
const { graph, outputNodeId, destination, prepend, timeout, signal } = arg ;
237
237
238
+ if ( ! graph . hasNode ( outputNodeId ) ) {
239
+ throw new Error ( `Graph does not contain node with id: ${ outputNodeId } ` ) ;
240
+ }
241
+
238
242
/**
239
243
* We will use the origin to handle events from the graph. Ideally we'd just use the queue item's id, but there's a
240
244
* race condition:
@@ -281,6 +285,7 @@ export class CanvasStateApiModule extends CanvasModuleBase {
281
285
if ( event . origin !== origin ) {
282
286
return ;
283
287
}
288
+
284
289
// Ignore events that are not from the output node
285
290
if ( event . invocation_source_id !== outputNodeId ) {
286
291
return ;
@@ -326,8 +331,19 @@ export class CanvasStateApiModule extends CanvasModuleBase {
326
331
clearListeners ( ) ;
327
332
328
333
if ( event . status === 'completed' ) {
329
- // If we get a queue item completed event, that means we never got a completion event for the output node!
330
- reject ( new Error ( 'Queue item completed without output node completion event' ) ) ;
334
+ /**
335
+ * The invocation_complete event should have been received before the queue item completed event, and the
336
+ * event listeners are cleared in the invocation_complete handler. If we get here, it means we never got
337
+ * the completion event for the output node! This should is a fail case.
338
+ *
339
+ * TODO(psyche): In the unexpected case where events are received out of order, this logic doesn't do what
340
+ * we expect. If we got a queue item completed event before the output node completion event, we'd erroneously
341
+ * triggers this error.
342
+ *
343
+ * For now, we'll just log a warning instead of rejecting the promise. This should be super rare anyways.
344
+ */
345
+ this . log . warn ( 'Queue item completed without output node completion event' ) ;
346
+ // reject(new Error('Queue item completed without output node completion event'));
331
347
} else if ( event . status === 'failed' ) {
332
348
// We expect the event to have error details, but technically it's possible that it doesn't
333
349
const { error_type, error_message, error_traceback } = event ;
0 commit comments