feat(uI): improved error handling when getting composite canvas images

Wrap logic that might throw in a result and handle log it if it errors before throwing.
This commit is contained in:
psychedelicious
2024-12-17 10:31:08 +10:00
parent 6b0f7ab57c
commit 9cecdd17eb

View File

@@ -277,13 +277,19 @@ export class CanvasCompositorModule extends CanvasModuleBase {
this.log.warn({ rect, imageName: cachedImageName }, 'Cached image name not found, recompositing');
}
const canvas = this.getCompositeCanvas(adapters, rect, compositingOptions);
const getCompositeCanvasResult = withResult(() => this.getCompositeCanvas(adapters, rect, compositingOptions));
if (getCompositeCanvasResult.isErr()) {
this.log.error({ error: serializeError(getCompositeCanvasResult.error) }, 'Failed to get composite canvas');
throw getCompositeCanvasResult.error;
}
this.$isProcessing.set(true);
const blobResult = await withResultAsync(() => canvasToBlob(canvas));
const blobResult = await withResultAsync(() => canvasToBlob(getCompositeCanvasResult.value));
this.$isProcessing.set(false);
if (blobResult.isErr()) {
this.log.error({ error: serializeError(blobResult.error) }, 'Failed to convert composite canvas to blob');
throw blobResult.error;
}
const blob = blobResult.value;