diff --git a/packages/ffmpeg/src/classes.ts b/packages/ffmpeg/src/classes.ts index 48d9e2c4a4..dd7ffacecd 100644 --- a/packages/ffmpeg/src/classes.ts +++ b/packages/ffmpeg/src/classes.ts @@ -18,7 +18,7 @@ import { FFFSPath, } from "./types.js"; import { getMessageID } from "./utils.js"; -import { ERROR_TERMINATED, ERROR_NOT_LOADED } from "./errors.js"; +import { ERROR_TERMINATED, ERROR_NOT_LOADED, ERROR_WORKER } from "./errors.js"; type FFMessageOptions = { signal?: AbortSignal; @@ -87,6 +87,16 @@ export class FFmpeg { delete this.#resolves[id]; delete this.#rejects[id]; }; + this.#worker.onerror = () => { + const rejects = { ...this.#rejects }; + this.#rejects = {}; + this.#resolves = {}; + this.#worker = null; + this.loaded = false; + for (const reject of Object.values(rejects)) { + reject(ERROR_WORKER); + } + }; } }; diff --git a/packages/ffmpeg/src/errors.ts b/packages/ffmpeg/src/errors.ts index d7246c79ec..6901e107a4 100644 --- a/packages/ffmpeg/src/errors.ts +++ b/packages/ffmpeg/src/errors.ts @@ -6,3 +6,6 @@ export const ERROR_TERMINATED = new Error("called FFmpeg.terminate()"); export const ERROR_IMPORT_FAILURE = new Error( "failed to import ffmpeg-core.js" ); +export const ERROR_WORKER = new Error( + "worker encountered an error, this is most likely caused by the worker script failing to load (CORP, network error, 404, etc.)" +);