Skip to content

Commit a2da064

Browse files
author
Kyle Keating
committed
Handle asynchronous exceptions in CodeRun
1 parent 68f0f97 commit a2da064

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/models/actions/CodeRun.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@ const { BaseAction } = require("./BaseAction");
22
const { performance } = require("perf_hooks");
33
const { NodeVM } = require("vm2");
44

5-
process.on("uncaughtException", () => {
5+
let resolve = null;
6+
let t0 = 0;
7+
8+
process.on("uncaughtException", (e) => {
9+
if (resolve) {
10+
resolve({
11+
actionReports: [
12+
{
13+
action: "Code.run",
14+
success: false,
15+
shortSummary: e.message || e,
16+
longSummary: null,
17+
time: performance.now() - t0,
18+
},
19+
],
20+
});
21+
}
622
// Do not delete!
723
//
824
// Used to catch asynchronous exceptions from inside of CodeRun that will otherwise
@@ -14,8 +30,9 @@ process.on("uncaughtException", () => {
1430

1531
class CodeRun extends BaseAction {
1632
async eval(context) {
17-
return new Promise((resolve) => {
18-
const t0 = performance.now();
33+
return new Promise((_resolve) => {
34+
resolve = _resolve;
35+
t0 = performance.now();
1936
const vm = new NodeVM({
2037
timeout: 60000,
2138
eval: false,

0 commit comments

Comments
 (0)