From b7a0e50b920961aac4d29619f721a4f915221df1 Mon Sep 17 00:00:00 2001 From: James Johnson Date: Fri, 18 Jul 2025 12:15:03 +1000 Subject: [PATCH] TINY-12536: Loader catches and reports errors from `tinymce.init` (#10473) --- .../mcagar-TINY-12536-2025-07-16.yaml | 6 +++ .../src/main/ts/ephox/mcagar/loader/Loader.ts | 54 ++++++++++--------- 2 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 .changes/unreleased/mcagar-TINY-12536-2025-07-16.yaml diff --git a/.changes/unreleased/mcagar-TINY-12536-2025-07-16.yaml b/.changes/unreleased/mcagar-TINY-12536-2025-07-16.yaml new file mode 100644 index 0000000000..806a73633f --- /dev/null +++ b/.changes/unreleased/mcagar-TINY-12536-2025-07-16.yaml @@ -0,0 +1,6 @@ +project: mcagar +kind: Fixed +body: Loader will catch errors thrown by `tinymce.init` and report them to the caller. +time: 2025-07-16T14:36:55.407731349+10:00 +custom: + Issue: TINY-12536 diff --git a/modules/mcagar/src/main/ts/ephox/mcagar/loader/Loader.ts b/modules/mcagar/src/main/ts/ephox/mcagar/loader/Loader.ts index 32d5c9c666..5560e0df03 100644 --- a/modules/mcagar/src/main/ts/ephox/mcagar/loader/Loader.ts +++ b/modules/mcagar/src/main/ts/ephox/mcagar/loader/Loader.ts @@ -1,5 +1,5 @@ import { TestLogs } from '@ephox/agar'; -import { Arr, Fun, FutureResult, Global, Id, Optional, Result } from '@ephox/katamari'; +import { Arr, Fun, FutureResult, Global, Id, Optional, Result, Type } from '@ephox/katamari'; import { Attribute, DomEvent, Insert, Remove, SelectorFilter, SugarBody, SugarElement, SugarHead, SugarShadowDom } from '@ephox/sugar'; import { Editor } from '../alien/EditorTypes'; @@ -74,7 +74,8 @@ const setup = (callbacks: Callbacks, settings: Record, elementOpt: }; // Agar v. ??? supports logging - const onFailure = (err: Error | string, logs?: TestLogs) => { + const onFailure = (errU: unknown, logs?: TestLogs) => { + const err = Type.isString(errU) || errU instanceof Error ? errU : String(errU); // eslint-disable-next-line no-console console.log('Tiny Loader error: ', err); // Do no teardown so that the failed test still shows the editor. Important for selection @@ -88,31 +89,34 @@ const setup = (callbacks: Callbacks, settings: Record, elementOpt: callbacks.preInit(tinymce, settings); const targetSettings = SugarShadowDom.isInShadowRoot(target) ? ({ target: target.dom }) : ({ selector: '#' + randomId }); + try { + Promise.resolve(tinymce.init({ + promotion: false, + license_key: 'gpl', + ...settings, + ...targetSettings, + setup: (editor: Editor) => { + // Execute the setup called by the test. + settingsSetup(editor); - tinymce.init({ - promotion: false, - license_key: 'gpl', - ...settings, - ...targetSettings, - setup: (editor: Editor) => { - // Execute the setup called by the test. - settingsSetup(editor); + editor.once('SkinLoaded', () => { + setTimeout(() => { + try { + callbacks.run(editor, onSuccess, onFailure); + } catch (e: any) { + onFailure(e); + } + }, 100); + }); - editor.once('SkinLoaded', () => { - setTimeout(() => { - try { - callbacks.run(editor, onSuccess, onFailure); - } catch (e: any) { - onFailure(e); - } - }, 100); - }); - - editor.once('SkinLoadError', (e) => { - callbacks.failure(e.message); - }); - } - }); + editor.once('SkinLoadError', (e) => { + callbacks.failure(e.message); + }); + } + })).catch(onFailure); + } catch (err: unknown) { + onFailure(err); + } }; if (!Global.tinymce) {