When a Lua error occurs, report it and jump to source of occurance (best
effort)
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ import "./lib/polyfills.ts";
|
||||
import type { BootConfig, ServiceWorkerTargetMessage } from "./types/ui.ts";
|
||||
import { BoxProxy } from "./lib/box_proxy.ts";
|
||||
import { importKey } from "@silverbulletmd/silverbullet/lib/crypto";
|
||||
|
||||
import "./debug.ts";
|
||||
const logger = initLogger("[Client]");
|
||||
|
||||
safeRun(async () => {
|
||||
|
||||
@@ -81,6 +81,8 @@ import { Augmenter } from "./data/data_augmenter.ts";
|
||||
import { EncryptedKvPrimitives } from "./data/encrypted_kv_primitives.ts";
|
||||
import type { KvPrimitives } from "./data/kv_primitives.ts";
|
||||
import { deriveDbName } from "@silverbulletmd/silverbullet/lib/crypto";
|
||||
import { LuaRuntimeError } from "./space_lua/runtime.ts";
|
||||
import { resolveASTReference } from "./space_lua.ts";
|
||||
|
||||
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
|
||||
|
||||
@@ -566,6 +568,18 @@ export class Client {
|
||||
);
|
||||
}
|
||||
|
||||
reportError(e: any, context: string = "") {
|
||||
console.error(`Error during ${context}:`, e);
|
||||
|
||||
if (e instanceof LuaRuntimeError) {
|
||||
client.flashNotification(`Lua error: ${e.message}`, "error");
|
||||
const origin = resolveASTReference(e.sf.astCtx!);
|
||||
if (origin) {
|
||||
client.navigate(origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startPageNavigate(mode: "page" | "meta" | "document" | "all") {
|
||||
// Then show the page navigator
|
||||
this.ui.viewDispatch({ type: "start-navigate", mode });
|
||||
|
||||
@@ -341,11 +341,7 @@ export function createCommandKeyBindings(client: Client): KeyBinding[] {
|
||||
Promise.resolve([])
|
||||
.then(def.run)
|
||||
.catch((e: any) => {
|
||||
console.error(e);
|
||||
client.flashNotification(
|
||||
`Error running command: ${e.message}`,
|
||||
"error",
|
||||
);
|
||||
client.reportError(e, "key");
|
||||
}).then((returnValue: any) => {
|
||||
// Always be focusing the editor after running a command
|
||||
if (returnValue !== false) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
globalThis.addEventListener("unhandledrejection", (event) => {
|
||||
client.reportError(event.reason);
|
||||
});
|
||||
@@ -224,7 +224,7 @@ export class MainUI {
|
||||
client.focus();
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error("Error running command", e.message);
|
||||
this.client.reportError(e, "Command invocation");
|
||||
}
|
||||
} else {
|
||||
setTimeout(() => client.focus());
|
||||
|
||||
Reference in New Issue
Block a user