Better plugin error handling

This commit is contained in:
Gregory Schier
2026-01-02 10:20:44 -08:00
parent 0146ee586f
commit 11694921e3
4 changed files with 533 additions and 381 deletions

View File

@@ -1,5 +1,5 @@
import type { PluginContext } from '@yaakapp-internal/plugins';
import type { BootRequest, InternalEvent } from '@yaakapp/api';
import type { PluginContext } from '@yaakapp-internal/plugins';
import type { EventChannel } from './EventChannel';
import { PluginInstance, type PluginWorkerData } from './PluginInstance';

View File

@@ -69,15 +69,25 @@ export class PluginInstance {
const fileChangeCallback = async () => {
await this.#mod?.dispose?.();
this.#importModule();
await this.#mod?.init?.(this.#newCtx(workerData.context));
return this.#sendPayload(
workerData.context,
{
type: 'reload_response',
silent: false,
},
null,
);
const ctx = this.#newCtx(workerData.context);
try {
await this.#mod?.init?.(ctx);
this.#sendPayload(
workerData.context,
{
type: 'reload_response',
silent: false,
},
null,
);
} catch (err: unknown) {
ctx.toast.show({
message: `Failed to initialize plugin ${this.#workerData.bootRequest.dir.split('/').pop()}: ${err}`,
color: 'notice',
icon: 'alert_triangle',
timeout: 30000,
});
}
};
if (this.#workerData.bootRequest.watch) {