prosemirror-math icon indicating copy to clipboard operation
prosemirror-math copied to clipboard

MathView throws unknown errors instead of handling them like ParseError

Open dragonman225 opened this issue 4 years ago • 1 comments

Hi benrbray,

Thank you for this great library, I have integrated it into the editor of Jade, my side-project to build a spatial note-taking tool.

An issue I notice recently is that MathView throws the KaTeX error if it's not a ParseError. It happens, for example, when I type this invalid LaTeX: \gdef\bar#1#{#1^2} \bar{y} + \bar{y}.

try {
	katex.render(texString, this._mathRenderElt, this._katexOptions);
	this._mathRenderElt.classList.remove("parse-error");
	this.dom.setAttribute("title", "");
} catch (err) {
	if (err instanceof ParseError) {
		console.error(err);
		this._mathRenderElt.classList.add("parse-error");
		this.dom.setAttribute("title", err.toString());
	} else {
		throw err; // <<
	}
}

Throwing the error means I need to handle it at higher level, or my app would crash. But when I catch the error in the app, I cannot easily know which MathView threw it and I have no access to _mathRenderElt to show the error message in place.

I think a better solution is to handle it the same way as handling ParseError: show the error message in place to notify users to correct their LaTeX. You can take a look at the approach in my fork here.

dragonman225 avatar Aug 26 '21 11:08 dragonman225

Good point, you're right. I'll try to include this in the next release.

benrbray avatar Aug 26 '21 16:08 benrbray