Skip to content

Commit

Permalink
Use _setUnhandledExceptionCallback to catch global exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Sep 17, 2023
1 parent a03c051 commit 2775949
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,37 @@ global.dump = function (x: any) {
console.log(JSON.stringify(x, null, 2));
}

global._setUnhandledExceptionCallback((error: Error) => {
const message = {
type: 'error',
error: '' + error,
message: '' + error,
description: '' + error,
stack: '',
fileName: '',
lineNumber: 0,
columnNumber: 0
};

if (error instanceof Error) {
const stack = error.stack;
if (stack !== undefined) {
message.stack = stack;
}

const fileName = (error as any).fileName;
if (fileName !== undefined) {
message.fileName = fileName;
}

const lineNumber = (error as any).lineNumber;
if (lineNumber !== undefined) {
message.lineNumber = lineNumber;
message.columnNumber = 1;
}
}

send(utils.wrapStanza('reply', message), []);
});

recv(onStanza);

0 comments on commit 2775949

Please sign in to comment.