Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle error so that it is shown in both page and task manager #247

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: clean + test
Signed-off-by: lstocchi <lstocchi@redhat.com>
  • Loading branch information
lstocchi committed Oct 1, 2024
commit 9a9dd2e5364b0c6bb2e7bfc3686598eaa49267fb
3 changes: 1 addition & 2 deletions src/crc-setup.ts
Original file line number Diff line number Diff line change
@@ -25,12 +25,11 @@ export async function needSetup(): Promise<boolean> {
await execPromise(getCrcCli(), ['setup', '--check-only']);
return false;
} catch (e) {
console.log(e)
console.log(e);
return true;
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setUpCrc(askForPreset = false): Promise<boolean> {
if (askForPreset) {
const preset = await extensionApi.window.showInformationMessage(
5 changes: 3 additions & 2 deletions src/crc-start.spec.ts
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import { startCrc } from './crc-start.js';
import * as logProvider from './log-provider.js';
import * as daemon from './daemon-commander.js';
import type { StartInfo } from './types.js';
import { getLoggerCallback } from './util.js';

vi.mock('@podman-desktop/api', async () => {
return {
@@ -44,7 +45,7 @@ test('setUpCRC is skipped if already setup, it just perform the daemon start com
{
updateStatus: vi.fn(),
} as unknown as extensionApi.Provider,
{} as extensionApi.Logger,
getLoggerCallback(),
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger,
);
expect(setUpMock).not.toBeCalled();
@@ -65,7 +66,7 @@ test('set up CRC and then start the daemon', async () => {
{
updateStatus: vi.fn(),
} as unknown as extensionApi.Provider,
{} as extensionApi.Logger,
getLoggerCallback(),
{ logUsage: vi.fn() } as unknown as extensionApi.TelemetryLogger,
);
expect(setUpMock).toBeCalled();
5 changes: 2 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -30,7 +30,6 @@ import { CrcInstall } from './install/crc-install.js';

import { crcStatus } from './crc-status.js';
import { startCrc } from './crc-start.js';
import { needSetup, setUpCrc } from './crc-setup.js';
import { deleteCrc, registerDeleteCommand } from './crc-delete.js';
import { presetChangedEvent, saveConfig, syncPreferences } from './preferences.js';
import { stopCrc } from './crc-stop.js';
@@ -332,9 +331,9 @@ function registerOpenShiftLocalCluster(
start: async (ctx, logger) => {
provider.updateStatus('starting');
try {
await startCrc(provider, getLoggerCallback(ctx, logger,), telemetryLogger);
await startCrc(provider, getLoggerCallback(ctx, logger), telemetryLogger);
} catch (e) {
logger?.error(e);
logger.error(e);
throw e;
}
},
1 change: 0 additions & 1 deletion src/log-provider.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { Logger } from '@podman-desktop/api';
import type { DaemonCommander } from './daemon-commander.js';
import { commander } from './daemon-commander.js';

43 changes: 43 additions & 0 deletions src/util.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type * as extensionApi from '@podman-desktop/api';
import { expect, test, vi } from 'vitest';
import { getLoggerCallback } from './util';

test('check logger passed to getLoggerCallback is actually called with data', async () => {
const logMock = vi.fn();
const logger = {
log: logMock,
} as unknown as extensionApi.Logger;
const callback = getLoggerCallback(undefined, logger);
callback('data');
expect(logMock).toBeCalledWith('data');
});

test('check logger passed to getLoggerCallback is actually called with data', async () => {
const logMock = vi.fn();
const context = {
log: {
log: logMock,
},
} as unknown as extensionApi.LifecycleContext;
const callback = getLoggerCallback(context);
callback('data2');
expect(logMock).toBeCalledWith('data2');
});
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import * as os from 'node:os';
import { spawn } from 'node:child_process';
import * as fs from 'node:fs/promises';
import type { Preset } from './types.js';
import { LifecycleContext, Logger } from '@podman-desktop/api';
import type { LifecycleContext, Logger } from '@podman-desktop/api';

export const productName = 'OpenShift Local';
export const defaultPreset: Preset = 'openshift';