From 9bccf105f45853e2e8854116749c9b5830918054 Mon Sep 17 00:00:00 2001 From: Marc O'Morain Date: Thu, 19 Jul 2018 23:23:47 +0100 Subject: [PATCH] Recover from errors more nicely. There are two changes here. Firstly, detect when the call to get a stacktrace fails with `unknown-op` - this indicates that the cider middleware to get stack traces is not loaded. This lead to the second change: after I fixed the first issue (which is bug #112 I noticed that if you do not have the clojure stack trace middleware, you could not see the reason for compilation errors. So rather than get a stack trace when compilation fails, we can print the error message from the compilation operation. This makes compilation errors take only 1 line on the output panel, which is much nicer. Fixes #112 --- src/clojureEval.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/clojureEval.ts b/src/clojureEval.ts index f671196..21f6a3a 100644 --- a/src/clojureEval.ts +++ b/src/clojureEval.ts @@ -163,8 +163,14 @@ function evaluate(outputChannel: vscode.OutputChannel, showResults: boolean): vo response = nreplClient.evaluateFile(text, editor.document.fileName, session.id); } response.then(respObjs => { - if (!!respObjs[0].ex) - return handleError(outputChannel, selection, showResults, respObjs[0].session); + if (!!respObjs[0].ex) { + vscode.window.showErrorMessage("Compilation Error") + for (let error of respObjs.map((r) => r.err).filter((e) => e)) { + outputChannel.append(error); + } + return + } + return handleSuccess(outputChannel, showResults, respObjs); }) @@ -179,6 +185,11 @@ function handleError(outputChannel: vscode.OutputChannel, selection: vscode.Sele .then(stacktraceObjs => { const stacktraceObj = stacktraceObjs[0]; + if (stacktraceObj.status && stacktraceObj.status.indexOf("unknown-op") != -1) { + outputChannel.appendLine("Failed to run get a stacktrace: the cider.nrepl.middleware.stacktrace middleware in not loaded."); + return; + } + let errLine = stacktraceObj.line !== undefined ? stacktraceObj.line - 1 : 0; let errChar = stacktraceObj.column !== undefined ? stacktraceObj.column - 1 : 0;