Skip to content

Commit d458a5f

Browse files
committed
Quiet down ADB error logging further
1 parent 76d798b commit d458a5f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/interceptors/android/adb-commands.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const EMULATOR_HOST_IPS = [
1717
'10.0.3.2', // Genymotion localhost ip
1818
];
1919

20+
let reportedAdbConnError = false;
21+
2022
export function createAdbClient() {
2123
const client = adb.createClient({
2224
port: process.env['ANDROID_ADB_SERVER_PORT']
@@ -43,13 +45,14 @@ export function createAdbClient() {
4345
// We listen for errors and report them. This only happens if adbkit completely
4446
// fails to handle or listen to a connection error. We'd rather report that than crash.
4547
client.on('error', (e) => {
46-
if (isErrorLike(e) && e.code === 'ENOENT') {
47-
// No ADB available - that's fine, not notable at all
48-
return;
48+
// We only report the first error though. Note that most errors will also surface
49+
// elsewhere, e.g. as a rejection from the relevant promise. This is mostly here
50+
// for weird connection errors that might appear async elsewhere.
51+
if (!reportedAdbConnError) {
52+
reportedAdbConnError = true;
53+
console.log('ADB connection error:', e.message ?? e);
54+
logError(e);
4955
}
50-
51-
console.log('ADB client error:', e.message ?? e);
52-
logError(e);
5356
});
5457

5558
return client;
@@ -105,6 +108,7 @@ export const getConnectedDevices = batchCalls(
105108
e.code === 'ENOENT' || // No ADB available
106109
e.code === 'EACCES' || // ADB available, but we aren't allowed to run it
107110
e.code === 'EPERM' || // Permissions error launching ADB
111+
e.code === 'EBADF' || // ADB launch failed do to ulimit, I think?
108112
e.code === 'ECONNREFUSED' || // Tried to start ADB, but still couldn't connect
109113
e.code === 'ENOTDIR' || // ADB path contains something that's not a directory
110114
e.signal === 'SIGKILL' || // In some envs 'adb start-server' is always killed (why?)

src/interceptors/android/android-adb-interceptor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ export class AndroidAdbInterceptor implements Interceptor {
138138
await bringToFront(
139139
deviceClient,
140140
'tech.httptoolkit.android.v1/tech.httptoolkit.android.MainActivity'
141-
).catch(logError); // Not that important, so we continue if this fails somehow
141+
).catch(console.log); // Not that important, we continue if this fails somehow
142142

143143
await deviceClient.startActivity({
144144
wait: true,
145145
action: 'tech.httptoolkit.android.DEACTIVATE'
146-
});
146+
}).catch(console.log); // Ditto
147147

148148
closeReverseTunnel(deviceClient, port, port);
149149
})

0 commit comments

Comments
 (0)