Skip to content

Commit 2d7e2b2

Browse files
committed
Intercept SyntaxError exception in evaluator to diagnose errors in output
1 parent e87b89c commit 2d7e2b2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: src/harness/evaluatorImpl.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,17 @@ namespace evaluator {
168168
const base = vpath.dirname(file);
169169
const localRequire = (id: string) => this.import(id, base);
170170
const evaluateText = `(function (module, exports, require, __dirname, __filename, ${globalNames.join(", ")}) { ${text} })`;
171-
// eslint-disable-next-line no-eval
172-
const evaluateThunk = (void 0, eval)(evaluateText) as (module: any, exports: any, require: (id: string) => any, dirname: string, filename: string, ...globalArgs: any[]) => void;
173-
evaluateThunk.call(this.globals, module, module.exports, localRequire, vpath.dirname(file), file, ...globalArgs);
171+
try {
172+
// eslint-disable-next-line no-eval
173+
const evaluateThunk = (void 0, eval)(evaluateText) as (module: any, exports: any, require: (id: string) => any, dirname: string, filename: string, ...globalArgs: any[]) => void;
174+
evaluateThunk.call(this.globals, module, module.exports, localRequire, vpath.dirname(file), file, ...globalArgs);
175+
}
176+
catch (e) {
177+
if (e instanceof SyntaxError) {
178+
throw new Error(`Evaluation failed: ${e.message}\nSource text:\n\n${evaluateText.split(/\r?\n/g).map(s => ` ${s}`).join("\n")}`);
179+
}
180+
throw e;
181+
}
174182
}
175183
}
176184

0 commit comments

Comments
 (0)