Skip to content

Commit dabffb4

Browse files
committed
Report failed Electron injection errors
1 parent 48136ea commit dabffb4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/interceptors/electron.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Interceptor } from '.';
1212
import { HtkConfig } from '../config';
1313
import { delay } from '../util';
1414
import { getTerminalEnvVars } from './terminal/terminal-env-overrides';
15+
import { reportError, addBreadcrumb } from '../error-tracking';
1516

1617
const readFile = util.promisify(fs.readFile);
1718

@@ -67,6 +68,9 @@ export class ElectronInterceptor implements Interceptor {
6768

6869
this.debugClients[proxyPort] = this.debugClients[proxyPort] || [];
6970
this.debugClients[proxyPort].push(debugClient);
71+
debugClient.once('disconnect', () => {
72+
_.remove(this.debugClients[proxyPort], c => c === debugClient);
73+
});
7074

7175
const callFramePromise = new Promise<string>((resolve) => {
7276
debugClient!.Debugger.paused((stack) => {
@@ -80,8 +84,8 @@ export class ElectronInterceptor implements Interceptor {
8084

8185
const callFrameId = await callFramePromise;
8286

83-
// Patch in our various module overrides:
84-
await debugClient.Debugger.evaluateOnCallFrame({
87+
// Inside the Electron process, load our electron-intercepting JS.
88+
const injectionResult = await debugClient.Debugger.evaluateOnCallFrame({
8589
expression: `require("${
8690
// Inside the Electron process, load our electron-intercepting JS
8791
require.resolve('../../overrides/js/prepend-electron.js')
@@ -92,10 +96,18 @@ export class ElectronInterceptor implements Interceptor {
9296
callFrameId
9397
});
9498

99+
if (injectionResult.exceptionDetails) {
100+
const exception = injectionResult.exceptionDetails as any;
101+
102+
addBreadcrumb("Evaluate error", {
103+
message: exception && exception.description,
104+
data: injectionResult.exceptionDetails
105+
});
106+
107+
throw new Error("Failed to inject into Electron app");
108+
}
109+
95110
debugClient.Debugger.resume();
96-
debugClient.once('disconnect', () => {
97-
_.remove(this.debugClients[proxyPort], c => c === debugClient);
98-
});
99111
}
100112

101113
async deactivate(proxyPort: number | string): Promise<void> {

0 commit comments

Comments
 (0)