Skip to content

Commit 9941160

Browse files
committed
Report activation error messages & codes back from the API
1 parent 835007b commit 9941160

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/api/api-model.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,16 @@ export class ApiModel {
184184
addBreadcrumb(`Failed to activate ${id}`, { category: 'interceptor' });
185185
reportError(err);
186186
}
187-
return { success: false, metadata: activationError.metadata };
187+
return {
188+
success: false,
189+
metadata: activationError.metadata,
190+
error: activationError.reportable !== false
191+
? {
192+
code: activationError.code,
193+
message: activationError.message
194+
}
195+
: {}
196+
};
188197
}
189198
}
190199

src/interceptors/electron.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Interceptor } from '.';
1010

1111
import { HtkConfig } from '../config';
1212
import { delay } from '../util/promise';
13-
import { isErrorLike } from '../util/error';
13+
import { ErrorLike, isErrorLike } from '../util/error';
1414
import { canAccess, readFile } from '../util/fs';
1515
import { windowsClose } from '../util/process-management';
1616
import { getTerminalEnvVars, OVERRIDES_DIR } from './terminal/terminal-env-overrides';
@@ -80,6 +80,7 @@ export class ElectronInterceptor implements Interceptor {
8080

8181
let debugClient: ChromeRemoteInterface.Client | undefined;
8282
let retries = 10;
83+
let spawnError: ErrorLike | undefined;
8384

8485
appProcess.on('error', async (e) => {
8586
reportError(e);
@@ -92,10 +93,10 @@ export class ElectronInterceptor implements Interceptor {
9293
}
9394

9495
// If we're still in the process of debugging the app, give up.
95-
retries = -1;
96+
spawnError = e as ErrorLike;
9697
});
9798

98-
while (!debugClient && retries >= 0) {
99+
while (!debugClient && retries >= 0 && !spawnError) {
99100
try {
100101
debugClient = await ChromeRemoteInterface({
101102
host: '127.0.0.1',
@@ -110,6 +111,8 @@ export class ElectronInterceptor implements Interceptor {
110111
await delay(500);
111112
}
112113
}
114+
115+
if (spawnError) throw spawnError;
113116
if (!debugClient) throw new Error('Could not initialize CDP client');
114117

115118
this.debugClients[proxyPort] = this.debugClients[proxyPort] || [];

src/interceptors/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash';
22

33
import { HtkConfig } from '../config';
44
import { addShutdownHandler } from '../shutdown';
5+
import { ErrorLike } from '../util/error';
56

67
import { FreshFirefox } from './fresh-firefox';
78
import {
@@ -43,9 +44,23 @@ export interface Interceptor {
4344
deactivateAll(): Promise<void | {}>;
4445
}
4546

46-
export interface ActivationError extends Error {
47-
metadata?: any; // Any extra metadata with the failure, e.g. if it could be retried
48-
reportable?: boolean; // Set to false to disable reporting this error, it's normal
47+
export interface ActivationError extends ErrorLike {
48+
/**
49+
* Activation errors can have an extra `metadata` field, to share data with the
50+
* client which attempted the activation, e.g. whether it can be retried.
51+
*/
52+
metadata?: any;
53+
54+
/**
55+
* Errors should be thrown with reportable set to `false` if they're a 'normal'
56+
* event that shouldn't be logged or exposed to the user. For example, if it's a
57+
* temporary failure that will lead to a confirmation flow or similar.
58+
*
59+
* This disables error logging and reporting of failure details from the API
60+
* (it assumes that the metadata will expose any info required, since this is a
61+
* recognized failure case).
62+
*/
63+
reportable?: boolean;
4964
}
5065

5166
export function buildInterceptors(config: HtkConfig): _.Dictionary<Interceptor> {

0 commit comments

Comments
 (0)