From d6a1db1e7b260dc4c4553ccad0b0f89214d1b0c2 Mon Sep 17 00:00:00 2001
From: dakkar <dakkar@thenautilus.net>
Date: Thu, 20 Jun 2024 10:20:47 +0100
Subject: [PATCH] ugly work-around to prevent plugins from breaking timelines

as the comment says, this is a complicated interaction that must be
fixed upstream (I'm not going to fork aiscript for this!)

but at least this stops errors in plugins from completely breaking
Sharkey's frontend
---
 packages/frontend/src/plugin.ts | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/packages/frontend/src/plugin.ts b/packages/frontend/src/plugin.ts
index 81233a5a5e..a0a624ace7 100644
--- a/packages/frontend/src/plugin.ts
+++ b/packages/frontend/src/plugin.ts
@@ -28,10 +28,31 @@ export async function install(plugin: Plugin): Promise<void> {
 		},
 		log: (): void => {
 		},
-		err: (err): void => {
-			pluginLogs.value.get(plugin.id).push(`${err}`);
-			throw err; // install時のtry-catchに反応させる
-		},
+		/* dakkar 2024-06-20
+
+			passing an `err` triggers an unwanted side-effect inside the
+			AiScript Interpreter:
+
+			- the plugin code throws an exception of any kind (in the
+			specific case that made us look, it was `note.text.split(...)`
+			on a note with no text)
+
+			- the Interpreter's `handleError` calls `this.abort()` before
+			calling our `err`
+
+			- from that point on, every evaluation of that Interpreter object
+			returns null
+
+			- which, at least inside a noteViewInterruptor, causes all notes
+      to be replaced with a null
+
+			I'm reporting this problem upstream, in the meantime we'll have
+			to do without error logs
+		*/
+		// err: (err): void => {
+		// 	pluginLogs.value.get(plugin.id).push(`${err}`);
+		// 	throw err; // install時のtry-catchに反応させる
+		// },
 	});
 
 	initPlugin({ plugin, aiscript });