Skip to content

Commit 944af4d

Browse files
feat(ui): show unsupported gen mode toasts as warnings intead of errors
1 parent 5e001be commit 944af4d

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

invokeai/frontend/web/public/locales/en.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1328,8 +1328,8 @@
13281328
"unableToCopyDesc": "Your browser does not support clipboard access. Firefox users may be able to fix this by following ",
13291329
"unableToCopyDesc_theseSteps": "these steps",
13301330
"fluxFillIncompatibleWithT2IAndI2I": "FLUX Fill is not compatible with Text to Image or Image to Image. Use other FLUX models for these tasks.",
1331-
"imagen3IncompatibleGenerationMode": "Google Imagen3 supports Text to Image only. Ensure the bounding box is empty, or use other models for Image to Image, Inpainting and Outpainting tasks.",
1332-
"chatGPT4oIncompatibleGenerationMode": "ChatGPT 4o supports Text to Image and Image to Image. Use other models Inpainting and Outpainting tasks.",
1331+
"imagen3IncompatibleGenerationMode": "Google Imagen3 supports Text to Image only. Use other models for Image to Image, Inpainting and Outpainting tasks.",
1332+
"chatGPT4oIncompatibleGenerationMode": "ChatGPT 4o supports Text to Image and Image to Image only. Use other models Inpainting and Outpainting tasks.",
13331333
"problemUnpublishingWorkflow": "Problem Unpublishing Workflow",
13341334
"problemUnpublishingWorkflowDescription": "There was a problem unpublishing the workflow. Please try again.",
13351335
"workflowUnpublished": "Workflow Unpublished"

invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/enqueueRequestedLinear.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { AlertStatus } from '@invoke-ai/ui-library';
12
import { createAction } from '@reduxjs/toolkit';
23
import { logger } from 'app/logging/logger';
34
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
@@ -13,6 +14,7 @@ import { buildImagen3Graph } from 'features/nodes/util/graph/generation/buildIma
1314
import { buildSD1Graph } from 'features/nodes/util/graph/generation/buildSD1Graph';
1415
import { buildSD3Graph } from 'features/nodes/util/graph/generation/buildSD3Graph';
1516
import { buildSDXLGraph } from 'features/nodes/util/graph/generation/buildSDXLGraph';
17+
import { UnsupportedGenerationModeError } from 'features/nodes/util/graph/types';
1618
import { toast } from 'features/toast/toast';
1719
import { serializeError } from 'serialize-error';
1820
import { enqueueMutationFixedCacheKeyOptions, queueApi } from 'services/api/endpoints/queue';
@@ -60,15 +62,21 @@ export const addEnqueueRequestedLinear = (startAppListening: AppStartListening)
6062
});
6163

6264
if (buildGraphResult.isErr()) {
65+
let title = 'Failed to build graph';
66+
let status: AlertStatus = 'error';
6367
let description: string | null = null;
6468
if (buildGraphResult.error instanceof AssertionError) {
6569
description = extractMessageFromAssertionError(buildGraphResult.error);
70+
} else if (buildGraphResult.error instanceof UnsupportedGenerationModeError) {
71+
title = 'Unsupported generation mode';
72+
description = buildGraphResult.error.message;
73+
status = 'warning';
6674
}
6775
const error = serializeError(buildGraphResult.error);
6876
log.error({ error }, 'Failed to build graph');
6977
toast({
70-
status: 'error',
71-
title: 'Failed to build graph',
78+
status,
79+
title,
7280
description,
7381
});
7482
return;

invokeai/frontend/web/src/features/nodes/util/graph/generation/buildChatGPT4oGraph.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
getBoardField,
1414
selectPresetModifiedPrompts,
1515
} from 'features/nodes/util/graph/graphBuilderUtils';
16-
import type { GraphBuilderReturn } from 'features/nodes/util/graph/types';
16+
import { type GraphBuilderReturn, UnsupportedGenerationModeError } from 'features/nodes/util/graph/types';
1717
import { t } from 'i18next';
1818
import { selectMainModelConfig } from 'services/api/endpoints/models';
1919
import type { Equals } from 'tsafe';
@@ -24,7 +24,9 @@ const log = logger('system');
2424
export const buildChatGPT4oGraph = async (state: RootState, manager: CanvasManager): Promise<GraphBuilderReturn> => {
2525
const generationMode = await manager.compositor.getGenerationMode();
2626

27-
assert(generationMode === 'txt2img' || generationMode === 'img2img', t('toast.chatGPT4oIncompatibleGenerationMode'));
27+
if (generationMode !== 'txt2img' && generationMode !== 'img2img') {
28+
throw new UnsupportedGenerationModeError(t('toast.chatGPT4oIncompatibleGenerationMode'));
29+
}
2830

2931
log.debug({ generationMode }, 'Building GPT Image graph');
3032

invokeai/frontend/web/src/features/nodes/util/graph/generation/buildFLUXGraph.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import {
2222
getSizes,
2323
selectPresetModifiedPrompts,
2424
} from 'features/nodes/util/graph/graphBuilderUtils';
25-
import type { GraphBuilderReturn, ImageOutputNodes } from 'features/nodes/util/graph/types';
25+
import {
26+
type GraphBuilderReturn,
27+
type ImageOutputNodes,
28+
UnsupportedGenerationModeError,
29+
} from 'features/nodes/util/graph/types';
2630
import { t } from 'i18next';
2731
import { selectMainModelConfig } from 'services/api/endpoints/models';
2832
import type { Invocation } from 'services/api/types';
@@ -80,7 +84,9 @@ export const buildFLUXGraph = async (state: RootState, manager: CanvasManager):
8084
//
8185
// The other asserts above are just for sanity & type check and should never be hit, so they do not have
8286
// translations.
83-
assert(generationMode === 'inpaint' || generationMode === 'outpaint', t('toast.fluxFillIncompatibleWithT2IAndI2I'));
87+
if (generationMode === 'txt2img' || generationMode === 'img2img') {
88+
throw new UnsupportedGenerationModeError(t('toast.fluxFillIncompatibleWithT2IAndI2I'));
89+
}
8490

8591
// FLUX Fill wants much higher guidance values than normal FLUX - silently "fix" the value for the user.
8692
// TODO(psyche): Figure out a way to alert the user that this is happening - maybe return warnings from the graph

invokeai/frontend/web/src/features/nodes/util/graph/generation/buildImagen3Graph.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
getBoardField,
1212
selectPresetModifiedPrompts,
1313
} from 'features/nodes/util/graph/graphBuilderUtils';
14-
import type { GraphBuilderReturn } from 'features/nodes/util/graph/types';
14+
import { type GraphBuilderReturn, UnsupportedGenerationModeError } from 'features/nodes/util/graph/types';
1515
import { t } from 'i18next';
1616
import type { Equals } from 'tsafe';
1717
import { assert } from 'tsafe';
@@ -21,7 +21,9 @@ const log = logger('system');
2121
export const buildImagen3Graph = async (state: RootState, manager: CanvasManager): Promise<GraphBuilderReturn> => {
2222
const generationMode = await manager.compositor.getGenerationMode();
2323

24-
assert(generationMode === 'txt2img', t('toast.imagen3IncompatibleGenerationMode'));
24+
if (generationMode !== 'txt2img') {
25+
throw new UnsupportedGenerationModeError(t('toast.imagen3IncompatibleGenerationMode'));
26+
}
2527

2628
log.debug({ generationMode }, 'Building Imagen3 graph');
2729

invokeai/frontend/web/src/features/nodes/util/graph/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ export type GraphBuilderReturn = {
3232
seedFieldIdentifier?: FieldIdentifier;
3333
positivePromptFieldIdentifier: FieldIdentifier;
3434
};
35+
36+
export class UnsupportedGenerationModeError extends Error {
37+
constructor(message: string) {
38+
super(message);
39+
this.name = this.constructor.name;
40+
}
41+
}

0 commit comments

Comments
 (0)