Improve handling of webworker failures. - #1538
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1538 +/- ##
===========================================
- Coverage 86.93% 86.92% -0.02%
===========================================
Files 388 388
Lines 87571 87584 +13
Branches 3290 3291 +1
===========================================
+ Hits 76129 76130 +1
- Misses 11442 11454 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| public getLabel(node: N, _center: string = '', sep: string = ' '): string { | ||
| const adaptor = this.adaptor; | ||
| if (!this.webworker.ready) { | ||
| // return document.querySelector('.mjx-selected').textContent; |
There was a problem hiding this comment.
These comments are in connection to my comment:
An alternative (in a comment) is to use the text content of the selected element, but that might be pretty ugly. On the other hand, it would at least be specific to the node being walked.
I meant that as a question about whether to do it the way I have it, or to use the text content instead. I left those comment in there in case you wanted to try the other alternative. Let me know which you think is best.
| public getBraille(node: N): string { | ||
| const adaptor = this.adaptor; | ||
| if (!this.webworker.ready) { | ||
| // return document.querySelector('.mjx-selected').textContent; |
This PR sets things up to better handle failures in landing the speech worker or its maps, rather than just crash.
In
KeyExplorer.ts, we remove initial,(for when the speech is empty, as it will be if speech has failed). TheWord/Mathmessage is used when there should be speech, but speech hasn't been attached (i.e., speech has failed to be produced). This way, if the page is being read, you will at least get "math" as the output rather than nothing at all.In
speech.ts, the errors are always strings, not Error objects, so fixed that. InspeechError(), we only report non-empty messages (this is to help avoid getting a speech error for every math expression on the page when SRE fails; seeWebWorker.tsfor more).In
GeneratorPool.ts, if the worker failed to start, we produce a message indicating that rather than no speech or braille. An alternative (in a comment) is to use the text content of the selected element, but that might be pretty ugly. On the other hand, it would at least be specific to the node being walked.In
WebWorker.ts, we only report a termination warning once if the warning is the same. That way, if the worker doesn't load, you don't get a redundant warning for every expression on the page, but just one warning. We also don't throw an error when terminating if the worker hasn't started (since we need to terminate the tasks). Finally, we add some commands to handle failure to start the worker, and failure to load a map file. We check to see if the error already includes the path that failed, and if not add it ourselves.The
speech-worker.tsfile adds error handling to thegetMap()methods so that errors are reported back to MathJax rather than just logged to the console.Similarly, the HTMLAdaptor and NodeMixin adaptor are modified to include error trapping when the worker is started up.
Finally, the
asyncLoad()function is fixed to handlenode:references, which was lost somewhere along the line in the locale branch.