make frontend -> backend errors actually work

This commit is contained in:
Party Wumpus
2024-02-22 16:38:50 +00:00
parent a449181802
commit 89a4a69f6d
4 changed files with 40 additions and 14 deletions
@@ -70,8 +70,14 @@ export default function TestingVersionList() {
<Focusable style={{ height: '40px', marginLeft: 'auto', display: 'flex' }}>
<DialogButton
style={{ height: '40px', minWidth: '60px', marginRight: '10px' }}
onClick={() => {
downloadTestingVersion(version.id, version.head_sha);
onClick={async () => {
try {
await downloadTestingVersion(version.id, version.head_sha);
} catch (e) {
if (e instanceof Error) {
DeckyPluginLoader.toaster.toast({ title: 'Error Installing PR', body: e.message });
}
}
setSetting('branch', UpdateBranch.Testing);
}}
>
+14 -3
View File
@@ -30,10 +30,20 @@ interface ReplyMessage {
interface ErrorMessage {
type: MessageType.ERROR;
error: any;
error: { name: string; message: string; traceback: string | null };
id: number;
}
export class PyError extends Error {
pythonTraceback: string | null;
constructor(name: string, message: string, traceback: string | null) {
super(message);
this.name = `Python ${name}`;
this.pythonTraceback = traceback;
}
}
interface EventMessage {
type: MessageType.EVENT;
event: string;
@@ -45,7 +55,7 @@ type Message = CallMessage | ReplyMessage | ErrorMessage | EventMessage;
// Helper to resolve a promise from the outside
interface PromiseResolver<T> {
resolve: (res: T) => void;
reject: (error: string) => void;
reject: (error: PyError) => void;
promise: Promise<T>;
}
@@ -124,7 +134,8 @@ export class WSRouter extends Logger {
case MessageType.ERROR:
if (this.runningCalls.has(data.id)) {
this.runningCalls.get(data.id)!.reject(data.error);
let err = new PyError(data.error.name, data.error.message, data.error.traceback);
this.runningCalls.get(data.id)!.reject(err);
this.runningCalls.delete(data.id);
this.debug(`Rejected PY call ${data.id} with error`, data.error);
}