🩹 error handling in JetBrains
This commit is contained in:
parent
ed1a3da33c
commit
707590e414
7 changed files with 40 additions and 9 deletions
|
|
@ -66,6 +66,11 @@ export class Core {
|
|||
|
||||
const on = this.messenger.on.bind(this.messenger);
|
||||
|
||||
this.messenger.onError((err) => {
|
||||
console.error(err);
|
||||
this.messenger.request("errorPopup", { message: err.message });
|
||||
});
|
||||
|
||||
// New
|
||||
on("update/modelChange", (msg) => {
|
||||
this.selectedModelTitle = msg.data;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@ export class IpcMessenger {
|
|||
});
|
||||
}
|
||||
|
||||
private _onErrorHandlers: ((error: Error) => void)[] = [];
|
||||
|
||||
onError(handler: (error: Error) => void) {
|
||||
this._onErrorHandlers.push(handler);
|
||||
}
|
||||
|
||||
mock(data: any) {
|
||||
const d = JSON.stringify(data);
|
||||
this._handleData(Buffer.from(d));
|
||||
|
|
@ -63,8 +69,11 @@ export class IpcMessenger {
|
|||
} else {
|
||||
this.send(msg.messageType, response || {}, msg.messageId);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
console.warn(`Error running handler for "${msg.messageType}": `, e);
|
||||
this._onErrorHandlers.forEach((handler) => {
|
||||
handler(e);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -78,7 +87,7 @@ export class IpcMessenger {
|
|||
|
||||
private _handleData(data: Buffer) {
|
||||
const d = data.toString();
|
||||
const lines = d.split("\n").filter((line) => line.trim() !== "");
|
||||
const lines = d.split(/\r\n|\r|\n/).filter((line) => line.trim() !== "");
|
||||
lines.forEach((line) => this._handleLine(line));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,4 +119,5 @@ export interface IdeSettings {
|
|||
|
||||
export type ReverseProtocol = IdeProtocol & {
|
||||
getIdeSettings: [undefined, IdeSettings];
|
||||
errorPopup: [{ message: string }, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
import * as fs from "fs";
|
||||
import fetch, { RequestInit, Response } from "node-fetch";
|
||||
import { http, https } from "follow-redirects";
|
||||
import * as fs from "fs";
|
||||
import { HttpProxyAgent } from "http-proxy-agent";
|
||||
import { HttpsProxyAgent } from "https-proxy-agent";
|
||||
import { RequestOptions } from "..";
|
||||
import fetch, { RequestInit, Response } from "node-fetch";
|
||||
import tls from "tls";
|
||||
import { RequestOptions } from "..";
|
||||
|
||||
export function fetchwithRequestOptions(
|
||||
url: URL,
|
||||
init: RequestInit,
|
||||
requestOptions?: RequestOptions
|
||||
requestOptions?: RequestOptions,
|
||||
): Promise<Response> {
|
||||
const TIMEOUT = 7200; // 7200 seconds = 2 hours
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ export function fetchwithRequestOptions(
|
|||
: requestOptions?.caBundlePath;
|
||||
if (customCerts) {
|
||||
ca.push(
|
||||
...customCerts.map((customCert) => fs.readFileSync(customCert, "utf8"))
|
||||
...customCerts.map((customCert) => fs.readFileSync(customCert, "utf8")),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware {
|
|||
// esbuild needs permissions
|
||||
val esbuildPath = Paths.get(targetPath, "esbuild"+ (if (os == "win32") ".exe" else "")).toString()
|
||||
|
||||
val coreMessenger = CoreMessenger(esbuildPath, continueCorePath, ideProtocolClient);
|
||||
val coreMessenger = CoreMessenger(project, esbuildPath, continueCorePath, ideProtocolClient);
|
||||
continuePluginService.coreMessenger = coreMessenger
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package com.github.continuedev.continueintellijextension.`continue`
|
||||
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.io.OutputStreamWriter
|
||||
|
|
@ -6,12 +7,15 @@ import java.io.OutputStreamWriter
|
|||
import java.io.*
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.attribute.PosixFilePermission
|
||||
|
||||
class CoreMessenger(esbuildPath: String, continueCorePath: String, ideProtocolClient: IdeProtocolClient) {
|
||||
class CoreMessenger(private val project: Project, esbuildPath: String, continueCorePath: String, ideProtocolClient: IdeProtocolClient) {
|
||||
private val writer: OutputStreamWriter
|
||||
private val reader: BufferedReader
|
||||
private val process: Process
|
||||
|
|
@ -60,6 +64,12 @@ class CoreMessenger(esbuildPath: String, continueCorePath: String, ideProtocolCl
|
|||
};
|
||||
}
|
||||
|
||||
// Forward to webview
|
||||
if (forwardToWebview.contains(messageType)) {
|
||||
val continuePluginService = project.service<ContinuePluginService>()
|
||||
continuePluginService.sendToWebview(messageType, data, messageType)
|
||||
}
|
||||
|
||||
// Responses for messageId
|
||||
responseListeners[messageId]?.let { listener ->
|
||||
listener(data)
|
||||
|
|
@ -110,6 +120,11 @@ class CoreMessenger(esbuildPath: String, continueCorePath: String, ideProtocolCl
|
|||
"getBranch",
|
||||
"getIdeInfo",
|
||||
"getIdeSettings",
|
||||
"errorPopup"
|
||||
)
|
||||
|
||||
private val forwardToWebview = listOf<String>(
|
||||
"configUpdate"
|
||||
)
|
||||
|
||||
private fun setPermissions(destination: String) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.intellij.openapi.fileEditor.TextEditor
|
|||
import com.intellij.openapi.project.DumbAware
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.MessageType
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.ui.popup.Balloon
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory
|
||||
import com.intellij.openapi.vfs.*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue