Skip to content

Commit 6d9ff99

Browse files
committed
[cdp] properly handle exceptions inside Runtime.callFunctionOn
1 parent 3d02ec8 commit 6d9ff99

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

chobitsu/src/domains/Runtime.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,41 @@ export async function callFunctionOn(
4141
ctx = objManager.getObj(objectId)
4242
}
4343

44-
let object = await callFn(functionDeclaration, args, ctx);
45-
let result = objManager.wrap(object, {
46-
generatePreview: true,
47-
});
48-
if (params.returnByValue) {
49-
result.value = structuredClone(object);
44+
let object;
45+
let exception;
46+
let threw = false;
47+
try {
48+
object = await callFn(functionDeclaration, args, ctx);
49+
} catch (e) {
50+
exception = e;
51+
threw = true;
5052
}
5153

52-
return {
53-
result,
54+
const ret: any = {};
55+
56+
if (threw) {
57+
ret.exceptionDetails = {
58+
exceptionId: 1,
59+
text: "Uncaught",
60+
lineNumber: 0, // TODO
61+
columnNumber: 0, // TODO
62+
stackTrace: { callFrames: [] }, // TODO
63+
exception: objManager.wrap(exception, {
64+
generatePreview: true,
65+
})
66+
};
67+
} else {
68+
const result = objManager.wrap(object, {
69+
generatePreview: true,
70+
});
71+
if (params.returnByValue) {
72+
result.value = structuredClone(object);
73+
}
74+
75+
ret.result = result;
5476
}
77+
78+
return ret
5579
}
5680

5781
let isEnable = false

chobitsu/src/lib/objManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function getDescription(obj: any, self: any = obj) {
333333
} else if (subtype === 'regexp') {
334334
description = toStr(obj)
335335
} else if (subtype === 'error') {
336-
description = obj.stack
336+
description = obj.message + obj.stack;
337337
} else if (subtype === 'internal#entry') {
338338
if (obj.name) {
339339
description = `{"${toStr(obj.name)}" => "${toStr(obj.value)}"}`

0 commit comments

Comments
 (0)