From 9861dc993291cbdd1b930c3d866f4b805cc6e16a Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Fri, 26 Jan 2024 12:49:48 +0100 Subject: [PATCH] feat: display error --- .../src/managers/modelsManager.spec.ts | 33 ++++++++++++------- .../backend/src/managers/modelsManager.ts | 3 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/managers/modelsManager.spec.ts b/packages/backend/src/managers/modelsManager.spec.ts index 489706978..83f301309 100644 --- a/packages/backend/src/managers/modelsManager.spec.ts +++ b/packages/backend/src/managers/modelsManager.spec.ts @@ -7,6 +7,27 @@ import type { Webview } from '@podman-desktop/api'; import type { CatalogManager } from './catalogManager'; import type { ModelInfo } from '@shared/src/models/IModelInfo'; +const mocks = vi.hoisted(() => { + return { + showErrorMessageMock: vi.fn(), + }; +}); + +vi.mock('@podman-desktop/api', () => { + return { + fs: { + createFileSystemWatcher: () => ({ + onDidCreate: vi.fn(), + onDidDelete: vi.fn(), + onDidChange: vi.fn(), + }), + }, + window: { + showErrorMessage: mocks.showErrorMessageMock, + }, + }; +}); + beforeEach(() => { vi.resetAllMocks(); }); @@ -112,17 +133,6 @@ test('loadLocalModels should post a message with the message on disk and on cata const now = new Date(); mockFiles(now); - vi.mock('@podman-desktop/api', () => { - return { - fs: { - createFileSystemWatcher: () => ({ - onDidCreate: vi.fn(), - onDidDelete: vi.fn(), - onDidChange: vi.fn(), - }), - }, - }; - }); const postMessageMock = vi.fn(); let appdir: string; if (process.platform === 'win32') { @@ -292,4 +302,5 @@ test('deleteLocalModel fails to delete the model folder', async () => { }, ], }); + expect(mocks.showErrorMessageMock).toHaveBeenCalledOnce(); }); diff --git a/packages/backend/src/managers/modelsManager.ts b/packages/backend/src/managers/modelsManager.ts index 2b106ef8b..0c6e6224e 100644 --- a/packages/backend/src/managers/modelsManager.ts +++ b/packages/backend/src/managers/modelsManager.ts @@ -5,6 +5,7 @@ import { type Webview, fs as apiFs } from '@podman-desktop/api'; import { MSG_NEW_LOCAL_MODELS_STATE } from '@shared/Messages'; import type { CatalogManager } from './catalogManager'; import type { ModelInfo } from '@shared/src/models/IModelInfo'; +import * as podmanDesktopApi from '@podman-desktop/api'; export class ModelsManager { #modelsDir: string; @@ -116,7 +117,7 @@ export class ModelsManager { await fs.promises.rm(modelDir, { recursive: true }); this.#localModels.delete(modelId); } catch (err: unknown) { - console.error('unable to delete model', modelId, err); + await podmanDesktopApi.window.showErrorMessage(`Error deleting model ${modelId}. ${String(err)}`); } finally { this.#deleted.delete(modelId); await this.sendModelsInfo();