Fix: try to get error message

This commit is contained in:
eight 2018-09-25 21:55:55 +08:00
parent 3d32b0428b
commit 3c30bc3eb0
2 changed files with 9 additions and 5 deletions

View File

@ -689,13 +689,17 @@ onDOMscriptReady('/codemirror.js').then(() => {
}).then(() => {
errors.classList.add('hidden');
}).catch(err => {
if (Array.isArray(err)) err = err.join('\n');
if (err && editor && !isNaN(err.index)) {
let message;
if (Array.isArray(err)) {
message = err.join('\n');
} else if (err && editor && !isNaN(err.index)) {
const pos = editors[0].posFromIndex(err.index);
err = `${pos.line}:${pos.ch} ${err}`;
message = `${pos.line}:${pos.ch} ${err.message || String(err)}`;
} else {
message = err.message || String(err);
}
errors.classList.remove('hidden');
errors.onclick = () => messageBox.alert(String(err), 'pre');
errors.onclick = () => messageBox.alert(message, 'pre');
});
}
});

View File

@ -224,7 +224,7 @@ function createSourceEditor(style) {
}
const contents = Array.isArray(err) ?
$create('pre', err.join('\n')) :
[String(err)];
[err.message || String(err)];
if (Number.isInteger(err.index)) {
const pos = cm.posFromIndex(err.index);
contents[0] += ` (line ${pos.line + 1} col ${pos.ch + 1})`;