MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / show

Method show

src/lib/FancyError.ts:142–196  ·  view source on GitHub ↗

* Show an error by registered ID with context, or with explicit title/message/props. * * Usage with registered error ID: * FancyError.show('action:jump:label_not_found', { label: 'my_label', step: 5 }); * * Usage with explicit parameters (legacy): * FancyError.show('Error Title', 'Er

(idOrTitle: string, contextOrMessage?: ErrorContext | string, propsArg?: FancyErrorProps)

Source from the content-addressed store, hash-verified

140 * FancyError.show('Error Title', 'Error message', { prop: 'value' });
141 */
142 static show (idOrTitle: string, contextOrMessage?: ErrorContext | string, propsArg?: FancyErrorProps): void {
143 if (typeof MonogatariDebug === 'object' && Debug.currentLevel > 0) {
144 let title: string;
145 let message: string;
146 let props: FancyErrorProps;
147
148 // Check if this is a registered error ID
149 const template = FancyError.registry.get(idOrTitle);
150
151 if (template && typeof contextOrMessage !== 'string') {
152 // ID-based call: FancyError.show('error:id', { context })
153 const context = (contextOrMessage || {}) as ErrorContext;
154 title = FancyError.interpolate(template.title, context);
155 message = FancyError.interpolate(template.message, context);
156 props = FancyError.interpolateProps(template.props, context);
157
158 // Merge any additional context properties that look like display props
159 // (keys starting with capital letter or containing spaces) into the final props
160 for (const key of Object.keys(context)) {
161 if (/^[A-Z]/.test(key) || key.includes(' ')) {
162 props[key] = context[key];
163 }
164 }
165 } else {
166 // Legacy call: FancyError.show('title', 'message', { props })
167 title = idOrTitle || 'Error';
168 message = (contextOrMessage as string) || 'An error has occurred! Please check the console so you get more insight.';
169 props = propsArg || {};
170 }
171
172 const id = Util.uuid();
173
174 const error: QueuedError = {
175 id,
176 title,
177 message,
178 props
179 };
180
181 if ($_('[data-error]').isVisible()) {
182 FancyError.queue.unshift(error);
183 } else {
184 const showError = (): void => {
185 $_('body').prepend(FancyError.generateModalHtml(error));
186 FancyError.attachDismissHandler(id);
187 };
188
189 if ($_('body').length > 0) {
190 showError();
191 } else {
192 $_ready(showError);
193 }
194 }
195 }
196 }
197
198 static render (props: FancyErrorProps = {}): string {
199 let html = '<div class="error-section">';

Callers 15

index.jsFile · 0.45
registerComponentMethod · 0.45
unregisterComponentMethod · 0.45
scriptMethod · 0.45
setupMethod · 0.45
elementMethod · 0.45
_setupRegistryMethod · 0.45
willApplyMethod · 0.45
constructorMethod · 0.45
applyMethod · 0.45
revertMethod · 0.45
willApplyMethod · 0.45

Calls 4

interpolateMethod · 0.80
interpolatePropsMethod · 0.80
getMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected