mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add winston formatting support for error causes (#6576)
* Add winston formatting support for error causes Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix failing to run built version - Finally make logger fully injectable - Simplify startMainApplication to only have runMany(Sync) invocations to fix time of use bugs related to logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove legacy type enforced ipc to fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
a4d0451dec
commit
8dd1d1a8fa
28 files changed
+544
-506
No files matched your search
@@ -68,6 +68,7 @@ import applicationMenuItemCompositeInjectable from "../../../features/applicatio
|
||||
import { getCompositePaths } from "../../../common/utils/composite/get-composite-paths/get-composite-paths";
|
||||
import { discoverFor } from "./discovery-of-html-elements";
|
||||
import { findComposite } from "../../../common/utils/composite/find-composite/find-composite";
|
||||
import shouldStartHiddenInjectable from "../../../main/electron-app/features/should-start-hidden.injectable";
|
||||
|
||||
type Callback = (di: DiContainer) => void | Promise<void>;
|
||||
|
||||
@@ -313,11 +314,9 @@ export const getApplicationBuilder = () => {
|
||||
.map(toWindowWithHelpersFor(windowHelpers)),
|
||||
|
||||
get: (id) => {
|
||||
const applicationWindows = builder.applicationWindow.getAll();
|
||||
|
||||
const applicationWindow = applicationWindows.find(
|
||||
(window) => window.id === id,
|
||||
);
|
||||
const applicationWindow = builder.applicationWindow
|
||||
.getAll()
|
||||
.find((window) => window.id === id);
|
||||
|
||||
if (!applicationWindow) {
|
||||
throw new Error(`Tried to get application window with ID "${id}" but it was not found.`);
|
||||
@@ -327,9 +326,7 @@ export const getApplicationBuilder = () => {
|
||||
},
|
||||
|
||||
create: (id) => {
|
||||
const createApplicationWindow = mainDi.inject(
|
||||
createApplicationWindowInjectable,
|
||||
);
|
||||
const createApplicationWindow = mainDi.inject(createApplicationWindowInjectable);
|
||||
|
||||
createApplicationWindow(id);
|
||||
|
||||
@@ -656,11 +653,8 @@ export const getApplicationBuilder = () => {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
const startMainApplication = mainDi.inject(
|
||||
startMainApplicationInjectable,
|
||||
);
|
||||
|
||||
await startMainApplication(false);
|
||||
mainDi.override(shouldStartHiddenInjectable, () => true);
|
||||
await mainDi.inject(startMainApplicationInjectable);
|
||||
|
||||
applicationHasStarted = true;
|
||||
},
|
||||
@@ -672,21 +666,15 @@ export const getApplicationBuilder = () => {
|
||||
await callback(mainDi);
|
||||
}
|
||||
|
||||
const startMainApplication = mainDi.inject(
|
||||
startMainApplicationInjectable,
|
||||
);
|
||||
|
||||
await startMainApplication(true);
|
||||
mainDi.override(shouldStartHiddenInjectable, () => false);
|
||||
await mainDi.inject(startMainApplicationInjectable);
|
||||
|
||||
applicationHasStarted = true;
|
||||
|
||||
const applicationWindow = builder.applicationWindow.get(
|
||||
"first-application-window",
|
||||
);
|
||||
|
||||
assert(applicationWindow);
|
||||
|
||||
return applicationWindow.rendered;
|
||||
return builder
|
||||
.applicationWindow
|
||||
.get("first-application-window")
|
||||
.rendered;
|
||||
},
|
||||
|
||||
select: {
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
|
||||
import type { IpcRendererEvent } from "electron";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { onCorrect } from "../../common/ipc";
|
||||
import { Notifications } from "../components/notifications";
|
||||
import { defaultHotbarCells } from "../../common/hotbars/types";
|
||||
import { type ListNamespaceForbiddenArgs, clusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs } from "../../common/ipc/cluster";
|
||||
import { type ListNamespaceForbiddenArgs, clusterListNamespaceForbiddenChannel } from "../../common/ipc/cluster";
|
||||
import { hotbarTooManyItemsChannel } from "../../common/ipc/hotbar";
|
||||
|
||||
function HotbarTooManyItemsHandler(): void {
|
||||
@@ -23,15 +22,6 @@ interface Dependencies {
|
||||
}
|
||||
|
||||
export const registerIpcListeners = ({ listNamespacesForbiddenHandler }: Dependencies) => () => {
|
||||
onCorrect({
|
||||
source: ipcRenderer,
|
||||
channel: clusterListNamespaceForbiddenChannel,
|
||||
listener: listNamespacesForbiddenHandler,
|
||||
verifier: isListNamespaceForbiddenArgs,
|
||||
});
|
||||
onCorrect({
|
||||
source: ipcRenderer,
|
||||
channel: hotbarTooManyItemsChannel,
|
||||
listener: HotbarTooManyItemsHandler,
|
||||
verifier: (args: unknown[]): args is [] => args.length === 0,
|
||||
});};
|
||||
ipcRenderer.on(clusterListNamespaceForbiddenChannel, listNamespacesForbiddenHandler);
|
||||
ipcRenderer.on(hotbarTooManyItemsChannel, HotbarTooManyItemsHandler);
|
||||
};
|
||||
@@ -107,7 +107,7 @@ export class KubeWatchApi {
|
||||
unsubscribe.push(store.subscribe({ onLoadFailure, abortController: childController }));
|
||||
} catch (error) {
|
||||
if (!(error instanceof DOMException)) {
|
||||
this.log(Object.assign(new Error("Loading stores has failed"), { cause: error }), {
|
||||
this.log(new Error("Loading stores has failed", { cause: error }), {
|
||||
meta: { store, namespaces },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import BrowserConsole from "winston-transport-browserconsole";
|
||||
import { loggerTransportInjectionToken } from "../../common/logger/transports";
|
||||
|
||||
const browserLoggerTransportInjectable = getInjectable({
|
||||
id: "browser-logger-transport",
|
||||
instantiate: () => new BrowserConsole(),
|
||||
injectionToken: loggerTransportInjectionToken,
|
||||
});
|
||||
|
||||
export default browserLoggerTransportInjectable;
|
||||
+42
-79
@@ -7,30 +7,10 @@ import React from "react";
|
||||
import { ipcRenderer } from "electron";
|
||||
import * as proto from "../../../common/protocol-handler";
|
||||
import Url from "url-parse";
|
||||
import { onCorrect } from "../../../common/ipc";
|
||||
import type { LensProtocolRouterDependencies } from "../../../common/protocol-handler";
|
||||
import { foldAttemptResults, ProtocolHandlerInvalid, RouteAttempt } from "../../../common/protocol-handler";
|
||||
import { Notifications } from "../../components/notifications";
|
||||
|
||||
function verifyIpcArgs(args: unknown[]): args is [string, RouteAttempt] {
|
||||
if (args.length !== 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof args[0] !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (args[1]) {
|
||||
case RouteAttempt.MATCHED:
|
||||
case RouteAttempt.MISSING:
|
||||
case RouteAttempt.MISSING_EXTENSION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
interface Dependencies extends LensProtocolRouterDependencies {}
|
||||
|
||||
export class LensProtocolRouterRenderer extends proto.LensProtocolRouter {
|
||||
@@ -42,75 +22,58 @@ export class LensProtocolRouterRenderer extends proto.LensProtocolRouter {
|
||||
* This function is needed to be called early on in the renderers lifetime.
|
||||
*/
|
||||
public init(): void {
|
||||
onCorrect({
|
||||
channel: proto.ProtocolHandlerInternal,
|
||||
source: ipcRenderer,
|
||||
verifier: verifyIpcArgs,
|
||||
listener: (event, rawUrl, mainAttemptResult) => {
|
||||
const rendererAttempt = this._routeToInternal(new Url(rawUrl, true));
|
||||
ipcRenderer.on(proto.ProtocolHandlerInternal, (event, rawUrl: string, mainAttemptResult: RouteAttempt) => {
|
||||
const rendererAttempt = this._routeToInternal(new Url(rawUrl, true));
|
||||
|
||||
if (foldAttemptResults(mainAttemptResult, rendererAttempt) === RouteAttempt.MISSING) {
|
||||
if (foldAttemptResults(mainAttemptResult, rendererAttempt) === RouteAttempt.MISSING) {
|
||||
Notifications.shortInfo((
|
||||
<p>
|
||||
{"Unknown action "}
|
||||
<code>{rawUrl}</code>
|
||||
{". Are you on the latest version?"}
|
||||
</p>
|
||||
));
|
||||
}
|
||||
});
|
||||
ipcRenderer.on(proto.ProtocolHandlerExtension, async (event, rawUrl: string, mainAttemptResult: RouteAttempt) => {
|
||||
const rendererAttempt = await this._routeToExtension(new Url(rawUrl, true));
|
||||
|
||||
switch (foldAttemptResults(mainAttemptResult, rendererAttempt)) {
|
||||
case RouteAttempt.MISSING:
|
||||
Notifications.shortInfo((
|
||||
<p>
|
||||
{"Unknown action "}
|
||||
<code>{rawUrl}</code>
|
||||
{". Are you on the latest version?"}
|
||||
{". Are you on the latest version of the extension?"}
|
||||
</p>
|
||||
));
|
||||
}
|
||||
},
|
||||
});
|
||||
onCorrect({
|
||||
channel: proto.ProtocolHandlerExtension,
|
||||
source: ipcRenderer,
|
||||
verifier: verifyIpcArgs,
|
||||
listener: async (event, rawUrl, mainAttemptResult) => {
|
||||
const rendererAttempt = await this._routeToExtension(new Url(rawUrl, true));
|
||||
|
||||
switch (foldAttemptResults(mainAttemptResult, rendererAttempt)) {
|
||||
case RouteAttempt.MISSING:
|
||||
Notifications.shortInfo((
|
||||
<p>
|
||||
{"Unknown action "}
|
||||
<code>{rawUrl}</code>
|
||||
{". Are you on the latest version of the extension?"}
|
||||
</p>
|
||||
));
|
||||
break;
|
||||
case RouteAttempt.MISSING_EXTENSION:
|
||||
Notifications.shortInfo((
|
||||
<p>
|
||||
{"Missing extension for action "}
|
||||
<code>{rawUrl}</code>
|
||||
{". Not able to find extension in our known list. Try installing it manually."}
|
||||
</p>
|
||||
));
|
||||
break;
|
||||
}
|
||||
},
|
||||
});
|
||||
onCorrect({
|
||||
channel: ProtocolHandlerInvalid,
|
||||
source: ipcRenderer,
|
||||
listener: (event, error, rawUrl) => {
|
||||
Notifications.error((
|
||||
<>
|
||||
break;
|
||||
case RouteAttempt.MISSING_EXTENSION:
|
||||
Notifications.shortInfo((
|
||||
<p>
|
||||
{"Failed to route "}
|
||||
{"Missing extension for action "}
|
||||
<code>{rawUrl}</code>
|
||||
.
|
||||
{". Not able to find extension in our known list. Try installing it manually."}
|
||||
</p>
|
||||
<p>
|
||||
<b>Error:</b>
|
||||
{" "}
|
||||
{error}
|
||||
</p>
|
||||
</>
|
||||
));
|
||||
},
|
||||
verifier: (args): args is [string, string] => {
|
||||
return args.length === 2 && typeof args[0] === "string";
|
||||
},
|
||||
));
|
||||
break;
|
||||
}
|
||||
});
|
||||
ipcRenderer.on(ProtocolHandlerInvalid, (event, error: string, rawUrl: string) => {
|
||||
Notifications.error((
|
||||
<>
|
||||
<p>
|
||||
{"Failed to route "}
|
||||
<code>{rawUrl}</code>
|
||||
.
|
||||
</p>
|
||||
<p>
|
||||
<b>Error:</b>
|
||||
{" "}
|
||||
{error}
|
||||
</p>
|
||||
</>
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user