TINY-12536: Loader catches and reports errors from tinymce.init (#10473)

This commit is contained in:
James Johnson
2025-07-18 12:15:03 +10:00
committed by GitHub
parent 618c517059
commit b7a0e50b92
2 changed files with 35 additions and 25 deletions

View File

@ -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

View File

@ -1,5 +1,5 @@
import { TestLogs } from '@ephox/agar'; 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 { Attribute, DomEvent, Insert, Remove, SelectorFilter, SugarBody, SugarElement, SugarHead, SugarShadowDom } from '@ephox/sugar';
import { Editor } from '../alien/EditorTypes'; import { Editor } from '../alien/EditorTypes';
@ -74,7 +74,8 @@ const setup = (callbacks: Callbacks, settings: Record<string, any>, elementOpt:
}; };
// Agar v. ??? supports logging // 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 // eslint-disable-next-line no-console
console.log('Tiny Loader error: ', err); console.log('Tiny Loader error: ', err);
// Do no teardown so that the failed test still shows the editor. Important for selection // Do no teardown so that the failed test still shows the editor. Important for selection
@ -88,8 +89,8 @@ const setup = (callbacks: Callbacks, settings: Record<string, any>, elementOpt:
callbacks.preInit(tinymce, settings); callbacks.preInit(tinymce, settings);
const targetSettings = SugarShadowDom.isInShadowRoot(target) ? ({ target: target.dom }) : ({ selector: '#' + randomId }); const targetSettings = SugarShadowDom.isInShadowRoot(target) ? ({ target: target.dom }) : ({ selector: '#' + randomId });
try {
tinymce.init({ Promise.resolve(tinymce.init({
promotion: false, promotion: false,
license_key: 'gpl', license_key: 'gpl',
...settings, ...settings,
@ -112,7 +113,10 @@ const setup = (callbacks: Callbacks, settings: Record<string, any>, elementOpt:
callbacks.failure(e.message); callbacks.failure(e.message);
}); });
} }
}); })).catch(onFailure);
} catch (err: unknown) {
onFailure(err);
}
}; };
if (!Global.tinymce) { if (!Global.tinymce) {