Skip to content

Commit

Permalink
Intercept SyntaxError exception in evaluator to diagnose errors in ou…
Browse files Browse the repository at this point in the history
…tput
  • Loading branch information
rbuckton committed Sep 20, 2022
1 parent e87b89c commit 2d7e2b2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/harness/evaluatorImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,17 @@ namespace evaluator {
const base = vpath.dirname(file);
const localRequire = (id: string) => this.import(id, base);
const evaluateText = `(function (module, exports, require, __dirname, __filename, ${globalNames.join(", ")}) { ${text} })`;
// eslint-disable-next-line no-eval
const evaluateThunk = (void 0, eval)(evaluateText) as (module: any, exports: any, require: (id: string) => any, dirname: string, filename: string, ...globalArgs: any[]) => void;
evaluateThunk.call(this.globals, module, module.exports, localRequire, vpath.dirname(file), file, ...globalArgs);
try {
// eslint-disable-next-line no-eval
const evaluateThunk = (void 0, eval)(evaluateText) as (module: any, exports: any, require: (id: string) => any, dirname: string, filename: string, ...globalArgs: any[]) => void;
evaluateThunk.call(this.globals, module, module.exports, localRequire, vpath.dirname(file), file, ...globalArgs);
}
catch (e) {
if (e instanceof SyntaxError) {
throw new Error(`Evaluation failed: ${e.message}\nSource text:\n\n${evaluateText.split(/\r?\n/g).map(s => ` ${s}`).join("\n")}`);
}
throw e;
}
}
}

Expand Down

0 comments on commit 2d7e2b2

Please sign in to comment.