Skip to content

Commit

Permalink
feat: display error
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jan 26, 2024
1 parent 8ac95b8 commit 9861dc9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
33 changes: 22 additions & 11 deletions packages/backend/src/managers/modelsManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -292,4 +302,5 @@ test('deleteLocalModel fails to delete the model folder', async () => {
},
],
});
expect(mocks.showErrorMessageMock).toHaveBeenCalledOnce();
});
3 changes: 2 additions & 1 deletion packages/backend/src/managers/modelsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9861dc9

Please sign in to comment.