refactor: Cleanup error renderer

This commit is contained in:
Sidharth Vinod 2023-12-07 00:37:25 +05:30
parent 70b948fd17
commit 1d86cf01ad
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD

View File

@ -2,10 +2,9 @@ import { log } from '../../logger.js';
import type { Group, SVG } from '../../diagram-api/types.js'; import type { Group, SVG } from '../../diagram-api/types.js';
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js'; import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
import { configureSvgSize } from '../../setupGraphViewbox.js'; import { configureSvgSize } from '../../setupGraphViewbox.js';
import type { Diagram } from '../../Diagram.js';
/** /**
* Draws a an info picture in the tag with id: id based on the graph definition in text. * Draws an info picture in the tag with id: id based on the graph definition in text.
* *
* @param _text - Mermaid graph definition. * @param _text - Mermaid graph definition.
* @param id - The text for the error * @param id - The text for the error
@ -16,15 +15,15 @@ export const draw = (
_text: string, _text: string,
id: string, id: string,
version: string, version: string,
_diagramObject: Diagram, _diagramObject: unknown,
error?: Error error?: Error
) => { ) => {
log.debug('renering svg for syntax error\n'); log.debug('rendering svg for syntax error\n');
const svg: SVG = selectSvgElement(id); const svg: SVG = selectSvgElement(id);
const g: Group = svg.append('g'); const g: Group = svg.append('g');
if (error?.message?.includes('KaTeX')) { if (error?.message?.includes('KaTeX')) {
const title = error.message.split(': ')[0]; const title = error.message.split(': ')[0];
const body = error.message.replace(/[A-z]*:/, '').replace('KaTeX parse ', ''); const body = error.message.slice(title.length + 2).replace('KaTeX parse ', '');
g.append('foreignObject') g.append('foreignObject')
.attr('height', 100) .attr('height', 100)
.attr('width', 500) .attr('width', 500)