Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print full evaluation error to output window #2030

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 39 additions & 36 deletions src/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DEBUG_ANALYTICS } from './debugger/calva-debug';
import * as namespace from './namespace';
import * as replHistory from './results-output/repl-history';
import { formatAsLineComments } from './results-output/util';
import { getStateValue } from '../out/cljs-lib/cljs-lib';
import { getStateValue, prettyPrint } from '../out/cljs-lib/cljs-lib';
import { getConfig } from './config';
import * as replSession from './nrepl/repl-session';
import * as getText from './util/get-text';
Expand Down Expand Up @@ -156,7 +156,7 @@ async function evaluateCodeUpdatingUI(
if (err.length > 0) {
const errMsg = formatAsLineComments(err.join('\n'));
if (context.stacktrace) {
outputWindow.saveStacktrace(context.stacktrace);
outputWindow.saveStacktrace(context.stacktrace as any);
outputWindow.appendLine(errMsg, (_, afterResultLocation) => {
outputWindow.markLastStacktraceRange(afterResultLocation);
});
Expand All @@ -166,43 +166,46 @@ async function evaluateCodeUpdatingUI(
}
}
} catch (e) {
const cause = `"${context.stacktrace.message.replace(/\"/g, '\\"').trim()}"`;
const data = context.stacktrace.data ? `\n :data ${context.stacktrace.data}` : '';
const stacktrace = context.stacktrace.stacktrace
.map((item) => `[${outputWindow.stackEntryString(item)}]`)
.join('\n');

const formattedError = `#${context.stacktrace.class.trim()} {
:type ${context.stacktrace.class}
:cause ${cause}${data}
:trace [${stacktrace}]
}`;

if (showErrorMessage) {
const outputWindowError = err.length
? formatAsLineComments(err.join('\n'))
: formatAsLineComments(e);
outputWindow.appendLine(outputWindowError, async (resultLocation, afterResultLocation) => {
if (selection) {
const editorError = util.stripAnsi(err.length ? err.join('\n') : e);
const currentCursorPos = editor.selection.active;
if (options.comment) {
await addAsComment(
selection.start.character,
editorError,
selection,
editor,
editor.selection
);
}
if (!outputWindow.isResultsDoc(editor.document)) {
annotations.decorateSelection(
editorError,
selection,
editor,
currentCursorPos,
resultLocation,
annotations.AnnotationStatus.ERROR
);
if (!options.comment) {
annotations.decorateResults(editorError, true, selection, editor);
}
}
outputWindow.appendLine(prettyPrint(formattedError).value);

if (selection) {
const editorError = util.stripAnsi(err.length ? err.join('\n') : e);
const currentCursorPos = editor.selection.active;
if (options.comment) {
await addAsComment(
selection.start.character,
editorError,
selection,
editor,
editor.selection
);
}
if (context.stacktrace && context.stacktrace.stacktrace) {
outputWindow.markLastStacktraceRange(afterResultLocation);
if (!outputWindow.isResultsDoc(editor.document)) {
annotations.decorateSelection(
editorError,
selection,
editor,
currentCursorPos,
null,
annotations.AnnotationStatus.ERROR
);
if (!options.comment) {
annotations.decorateResults(editorError, true, selection, editor);
}
}
});
if (context.stacktrace && context.stacktrace.stacktrace) {
outputWindow.saveStacktrace(context.stacktrace.stacktrace);
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion src/nrepl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,20 @@ export class NReplSession {
}
}

type StackTraceItem = {
class: string;
file: string;
line: number;
method: string;
name: string;
type: string;
};
type NReplEvaluationErrorStackTrace = {
class: string;
message: string;
stacktrace: StackTraceItem[];
};

/**
* A running nREPL eval call.
*/
Expand All @@ -919,7 +933,7 @@ export class NReplEvaluation {

private _exception: string;

private _stacktrace: any;
private _stacktrace: NReplEvaluationErrorStackTrace | undefined | any;

private _msgs: any[] = [];

Expand Down Expand Up @@ -1093,6 +1107,7 @@ export class NReplEvaluation {
const cause = msg.causes[0];
const errorMessage = `${cause.class}: ${cause.message}`;
this._stacktrace = { stacktrace: cause.stacktrace };
console.log('HAS STATUS', msg);
this.err(errorMessage);
}
if (msg.value !== undefined || msg['debug-value'] !== undefined) {
Expand Down Expand Up @@ -1135,6 +1150,7 @@ export class NReplEvaluation {
this.session
.stacktrace()
.then((stacktrace) => {
console.log('GOT THING', stacktrace);
this._stacktrace = stacktrace;
this.doReject(this.exception);
})
Expand Down
2 changes: 1 addition & 1 deletion src/results-output/results-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export function getStacktraceEntryForKey(key: string): OutputStacktraceEntry {
return _stacktraceEntries[key];
}

function stackEntryString(entry: any): string {
export function stackEntryString(entry: any): string {
const name = entry.var || entry.name;
return `${name} (${entry.file}:${entry.line})`;
}
Expand Down