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:
Sebastian Malton authored and GitHub committed 2022-11-17 14:56:16 +02:00
1 parent a4d0451dec
commit 8dd1d1a8fa
28 files changed
+544 -506

No files matched your search

@@ -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>
</>
));
});
}
}