Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for trapping and reporting sre errors. #679

Merged
merged 3 commits into from
Apr 21, 2021
Merged

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Apr 2, 2021

This PR adds support for trapping and reporting errors that occur during the SRE enrichment process. It adds a new enrichError(), comparable to the compileError() and typesetError() options, that allows you to capture the error and respond to it. The default is to just issue a console warning, and to use the original (unenriched) MathML, but you could use this to present a different representation, or record the message, or whatever.

This also changes the inputData that is being kept so that originalMml is the original serialization of the internal MathML, and enrichedMml is the serialized enriched MathML (which used to be stored a originalMml, which doesn't seem right). No other component currently uses this data, so it should be OK to make this change.

@dpvc dpvc added this to the 3.1.3 milestone Apr 2, 2021
@dpvc dpvc requested a review from zorkow April 2, 2021 14:52
Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this approach is that only works in the case where SRE actually fails to return something. If it returns valid something that cannot be rendered, then the menu fails on opening due to the cs preferences.

@zorkow
Copy link
Member

zorkow commented Apr 20, 2021

Replacing lines

const items = sre.ClearspeakPreferences.smartPreferences(

to

by

  let items = null;
  try {
    items = sre.ClearspeakPreferences.smartPreferences(
      menu.mathItem, locale);
    if (box) {
      items.splice(2, 0, box);
    }
  } catch (e) {}
  return menu.factory.get('subMenu')(menu.factory, {
    items: items || [],
    id: 'Clearspeak'
  }, sub);

will take care of the problem.

In the future this should really be caught in SRE and/or the context menu not here. But it will work as a temporary fix here.

@dpvc
Copy link
Member Author

dpvc commented Apr 20, 2021

I'm not sure I understand what you are saying, but am happy to add the code you suggest. One question, though: The current code (without your new try statement) performs the smartPreferences() call, the conditional item.splice() and the menu.factory.get() call, but with the try you get either just the first two, or just the last one, but not both. Is that what is intended?

@zorkow
Copy link
Member

zorkow commented Apr 21, 2021

I note, my sentence was incomplete. Sorry, fatigue.
I meant "if SRE returns valid enriched markup, but that cannot be rendered", e.g., due to a third party parser (my use case was the xypic extension) then there is an error in SRE that is currently not being caught.

I originally thought that if the smart preferences fail, there is really no need to compute the selection preferences. But in hindsight this is probably not smart, as they could fail on non-error elements as well. So I suggest this:

let csMenu = function(menu: MJContextMenu, sub: Submenu) {
  let locale = menu.pool.lookup('locale').getValue() as string;
  const box = csSelectionBox(menu, locale);
  let items: Object[] = [];
  try {
    items = sre.ClearspeakPreferences.smartPreferences(
      menu.mathItem, locale);
  } catch (e) {}
  if (box) {
    items.splice(2, 0, box);
  }
  return menu.factory.get('subMenu')(menu.factory, {
    items: items,
    id: 'Clearspeak'
  }, sub);
};

@dpvc
Copy link
Member Author

dpvc commented Apr 21, 2021

if SRE returns valid enriched markup, but that cannot be rendered, e.g., due to a third party parser (my use case was the xypic extension) then there is an error in SRE that is currently not being caught.

If by "rendering" you mean by an output jax, then there is already a trap for failure to render (typesetError()), and that can be used to catch the error. But the important part is, it doesn't stop MathJax from continuing to process other math, which the SRE failure trapped here would. Without this, if SRE fails to produce a result, MathJax will crash and not finish processing the rest of the math. That is why this change is useful. (We already have that for compiling and typesetting.)

It may be that a more general solution would be useful, where each renderAction is run inside a try/catch block. Then we wouldn't need the special cases for compile/typeset/enrich. If so, we can do that for 3.2.0.

@dpvc
Copy link
Member Author

dpvc commented Apr 21, 2021

So I suggest this ...

I've made the requested change.

@dpvc
Copy link
Member Author

dpvc commented Apr 21, 2021

I also resolved the conflict.

@dpvc
Copy link
Member Author

dpvc commented Apr 21, 2021

If you want to wait with this for v3.2 and a more general solution, I'm OK with that.

@dpvc dpvc requested a review from zorkow April 21, 2021 12:41
@zorkow
Copy link
Member

zorkow commented Apr 21, 2021

Even when the rendering error is caught, the menu error might prevent you from switching off whatever has caused the rendering error. Consider the scenario

  • Page with a single Math item.
  • Switching on a11y via the context menu leads to Math Output Error.
  • Error in the cs submenu prevents you from opening the context menu
  • Now you have no way of switching off a11y short of altering the localStorage

Let's keep it in for 3.1.3 and have a good cleanup of that part for 3.2.

Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@dpvc
Copy link
Member Author

dpvc commented Apr 21, 2021

Let's keep it in for 3.1.3 and have a good cleanup of that part for 3.2.

OK, good enough.

@dpvc dpvc merged commit 0b51a5f into develop Apr 21, 2021
@dpvc dpvc deleted the sre-errors branch April 21, 2021 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants