1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make startableStoppables have ID for better error logging

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-04-26 10:13:39 +03:00 committed by Janne Savolainen
parent 57a1677c48
commit 203418ac37
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
6 changed files with 13 additions and 18 deletions

View File

@ -13,7 +13,7 @@ describe("getStartableStoppable", () => {
stopMock = jest.fn(); stopMock = jest.fn();
startMock = jest.fn(() => stopMock); startMock = jest.fn(() => stopMock);
actual = getStartableStoppable(startMock); actual = getStartableStoppable("some-id", startMock);
}); });
it("does not start yet", () => { it("does not start yet", () => {
@ -27,7 +27,7 @@ describe("getStartableStoppable", () => {
it("when stopping before ever starting, throws", () => { it("when stopping before ever starting, throws", () => {
expect(() => { expect(() => {
actual.stop(); actual.stop();
}).toThrow("Tried to stop something that has not started yet."); }).toThrow("Tried to stop \"some-id\", but it has not started yet.");
}); });
describe("when started", () => { describe("when started", () => {
@ -42,7 +42,7 @@ describe("getStartableStoppable", () => {
it("when started again, throws", () => { it("when started again, throws", () => {
expect(() => { expect(() => {
actual.start(); actual.start();
}).toThrow("Tried to start something that has already started."); }).toThrow("Tried to start \"some-id\", but it has already started.");
}); });
it("does not stop yet", () => { it("does not stop yet", () => {
@ -61,7 +61,7 @@ describe("getStartableStoppable", () => {
it("when stopped again, throws", () => { it("when stopped again, throws", () => {
expect(() => { expect(() => {
actual.stop(); actual.stop();
}).toThrow("Tried to stop something that has already stopped."); }).toThrow("Tried to stop \"some-id\", but it has already stopped.");
}); });
describe("when started again", () => { describe("when started again", () => {

View File

@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
export const getStartableStoppable = ( export const getStartableStoppable = (
id: string,
startAndGetStopCallback: () => () => void, startAndGetStopCallback: () => () => void,
) => { ) => {
let dispose: () => void; let dispose: () => void;
@ -12,7 +13,7 @@ export const getStartableStoppable = (
return { return {
start: () => { start: () => {
if (started) { if (started) {
throw new Error("Tried to start something that has already started."); throw new Error(`Tried to start "${id}", but it has already started.`);
} }
stopped = false; stopped = false;
@ -24,11 +25,11 @@ export const getStartableStoppable = (
stop: () => { stop: () => {
if (stopped) { if (stopped) {
throw new Error("Tried to stop something that has already stopped."); throw new Error(`Tried to stop "${id}", but it has already stopped.`);
} }
if (!started) { if (!started) {
throw new Error("Tried to stop something that has not started yet."); throw new Error(`Tried to stop "${id}", but it has not started yet.`);
} }
started = false; started = false;

View File

@ -13,7 +13,7 @@ const catalogSyncToRendererInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
return getStartableStoppable(() => return getStartableStoppable("catalog-sync", () =>
startCatalogSyncToRenderer(catalogEntityRegistry), startCatalogSyncToRenderer(catalogEntityRegistry),
); );
}, },

View File

@ -56,11 +56,8 @@ import applicationMenuInjectable from "./menu/application-menu.injectable";
import windowManagerInjectable from "./window-manager.injectable"; import windowManagerInjectable from "./window-manager.injectable";
import isDevelopmentInjectable from "../common/vars/is-development.injectable"; import isDevelopmentInjectable from "../common/vars/is-development.injectable";
import setupSystemCaInjectable from "./start-main-application/before-application-is-ready/implementations/setup-system-ca.injectable"; import setupSystemCaInjectable from "./start-main-application/before-application-is-ready/implementations/setup-system-ca.injectable";
import whenApplicationWillQuitInjectable from "./electron-app/when-application-will-quit.injectable";
import setupDeepLinkingInjectable from "./electron-app/after-application-is-ready/setup-deep-linking.injectable"; import setupDeepLinkingInjectable from "./electron-app/after-application-is-ready/setup-deep-linking.injectable";
import whenSecondInstanceInjectable from "./electron-app/when-second-instance.injectable";
import exitAppInjectable from "./electron-app/features/exit-app.injectable"; import exitAppInjectable from "./electron-app/features/exit-app.injectable";
import setApplicationNameInjectable from "./electron-app/features/set-application-name.injectable";
import getCommandLineSwitchInjectable from "./electron-app/features/get-command-line-switch.injectable"; import getCommandLineSwitchInjectable from "./electron-app/features/get-command-line-switch.injectable";
import requestSingleInstanceLockInjectable from "./electron-app/features/request-single-instance-lock.injectable"; import requestSingleInstanceLockInjectable from "./electron-app/features/request-single-instance-lock.injectable";
import disableHardwareAccelerationInjectable from "./electron-app/features/disable-hardware-acceleration.injectable"; import disableHardwareAccelerationInjectable from "./electron-app/features/disable-hardware-acceleration.injectable";
@ -92,7 +89,7 @@ export const getDiForUnitTesting = (
if (doGeneralOverrides) { if (doGeneralOverrides) {
overrideOperatingSystem(di); overrideOperatingSystem(di);
overrideRunnablesHavingSideEffects(di); overrideRunnablesHavingSideEffects(di);
overrideElectron(di); overrideElectronFeatures(di);
di.override(isDevelopmentInjectable, () => false); di.override(isDevelopmentInjectable, () => false);
di.override(environmentVariablesInjectable, () => ({})); di.override(environmentVariablesInjectable, () => ({}));
@ -187,7 +184,7 @@ const overrideOperatingSystem = (di: DiContainer) => {
di.override(joinPathsInjectable, () => joinPathsFake); di.override(joinPathsInjectable, () => joinPathsFake);
}; };
const overrideElectron = (di: DiContainer) => { const overrideElectronFeatures = (di: DiContainer) => {
di.override(setupMainWindowVisibilityAfterActivationInjectable, () => ({ di.override(setupMainWindowVisibilityAfterActivationInjectable, () => ({
run: () => {}, run: () => {},
})); }));
@ -197,10 +194,7 @@ const overrideElectron = (di: DiContainer) => {
})); }));
di.override(setupDeepLinkingInjectable, () => ({ run: () => {} })); di.override(setupDeepLinkingInjectable, () => ({ run: () => {} }));
di.override(whenApplicationWillQuitInjectable, () => () => {});
di.override(whenSecondInstanceInjectable, () => () => {});
di.override(exitAppInjectable, () => () => {}); di.override(exitAppInjectable, () => () => {});
di.override(setApplicationNameInjectable, () => () => {});
di.override(getCommandLineSwitchInjectable, () => () => "irrelevant"); di.override(getCommandLineSwitchInjectable, () => () => "irrelevant");
di.override(requestSingleInstanceLockInjectable, () => () => true); di.override(requestSingleInstanceLockInjectable, () => () => true);
di.override(disableHardwareAccelerationInjectable, () => () => {}); di.override(disableHardwareAccelerationInjectable, () => () => {});

View File

@ -14,7 +14,7 @@ const applicationMenuInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const applicationMenuItems = di.inject(applicationMenuItemsInjectable); const applicationMenuItems = di.inject(applicationMenuItemsInjectable);
return getStartableStoppable(() => return getStartableStoppable("build-of-application-menu", () =>
autorun(() => buildMenu(applicationMenuItems.get()), { autorun(() => buildMenu(applicationMenuItems.get()), {
delay: 100, delay: 100,
}), }),

View File

@ -21,7 +21,7 @@ const trayInjectable = getInjectable({
const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable); const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable);
const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable); const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable);
return getStartableStoppable(() => return getStartableStoppable("build-of-tray", () =>
initTray( initTray(
windowManager, windowManager,
trayMenuItems, trayMenuItems,