From 3c30bc3eb014a9936d605425facbee4011ce4244 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 25 Sep 2018 21:55:55 +0800 Subject: [PATCH] Fix: try to get error message --- edit/codemirror-editing-hooks.js | 12 ++++++++---- edit/source-editor.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/edit/codemirror-editing-hooks.js b/edit/codemirror-editing-hooks.js index 31d0ce5d..a53bf618 100644 --- a/edit/codemirror-editing-hooks.js +++ b/edit/codemirror-editing-hooks.js @@ -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'); }); } }); diff --git a/edit/source-editor.js b/edit/source-editor.js index 4b91e4f2..28ec7f49 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -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})`;