Skip to content

Commit 504f473

Browse files
committed
[main] catch startup errors
Cf. #401 (comments)
1 parent e953e7a commit 504f473

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/main.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ var document, window, content, html; // the DOM elements
9191
var queue = []; // queue of typesetting requests of the form [data,callback]
9292
var data, callback, originalData; // the current queue item
9393
var errors = []; // errors collected durring the typesetting
94+
var sErrors = []; // errors collected durring MathJax startup
9495
var ID = 0; // id for this SVG element
9596

9697
//
@@ -519,7 +520,10 @@ function ConfigureMathJax() {
519520
if (MathJax.OutputJax.SVG.resetGlyphs) MathJax.OutputJax.SVG.resetGlyphs(true);
520521
MathJax.ElementJax.mml.ID = 0;
521522
serverState = STATE.READY;
522-
MathJax.Hub.Queue(StartQueue);
523+
MathJax.Hub.Queue(
524+
function () {sErrors = errors},
525+
StartQueue
526+
);
523527
});
524528
}
525529
};
@@ -730,7 +734,7 @@ function GetSVG(result) {
730734
//
731735
function StartQueue() {
732736
data = callback = originalData = null; // clear existing equation, if any
733-
errors = []; // clear any errors
737+
errors = sErrors; sErrors = []; // clear any errors
734738
if (!queue.length) return; // return if nothing to do
735739

736740
serverState = STATE.BUSY;

test/base-01-errors-startup.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var tape = require('tape');
2+
var mjAPI = require('../lib/main.js');
3+
4+
// NOTE this test must first (in tape) to test the startup phase (hence the filename contains "01")
5+
6+
tape('Catch errors during startup phase', function(t) {
7+
t.plan(1);
8+
mjAPI.config({
9+
extensions: 'blargh'
10+
});
11+
mjAPI.typeset(
12+
{
13+
math: 'x',
14+
format: 'TeX',
15+
mml: true
16+
},
17+
function(data) {
18+
t.ok(
19+
data.errors,
20+
'Error (loading non-existent extension) is caught in output'
21+
);
22+
// reset configuration
23+
mjAPI.config({
24+
extensions: 'tex2jax'
25+
});
26+
}
27+
);
28+
});

0 commit comments

Comments
 (0)