Skip to content

Commit dd05dd9

Browse files
committed
refactor(android): classify each adb attempt's outcome in its own helper
attemptAdb asks isOfflineRefusalResult or isOfflineRefusalError instead of reading the classification inline, which keeps it under the fallow complexity threshold.
1 parent c8c7741 commit dd05dd9

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎packages/platform-android/src/adb-provider-scope.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,12 @@ async function attemptAdb(
152152
): Promise<{ offline: boolean; outcome: () => AndroidAdbExecutorResult }> {
153153
try {
154154
const result = await run();
155-
const failure =
156-
result.exitCode === 0 ? undefined : classifyAndroidAdbFailure(result.stderr, result.stdout);
157-
const offline = isDeviceOfflineHostRefusal(failure?.reason, failure?.hostRefusal);
155+
const offline = isOfflineRefusalResult(result);
158156
if (!offline) devicesStayingOffline.forget(device);
159157
return { offline, outcome: () => result };
160158
} catch (error) {
161159
const classified = attachAdbFailureHint(error);
162-
const details = classified instanceof AppError ? classified.details : undefined;
163-
const offline = isDeviceOfflineHostRefusal(details?.adbFailure, details?.adbHostRefusal);
160+
const offline = isOfflineRefusalError(classified);
164161
if (!offline && deviceAnswered(classified)) devicesStayingOffline.forget(device);
165162
return {
166163
offline,
@@ -171,6 +168,22 @@ async function attemptAdb(
171168
}
172169
}
173170

171+
/** Whether the host adb refused the command for an offline device, as a result. */
172+
function isOfflineRefusalResult(result: AndroidAdbExecutorResult): boolean {
173+
if (result.exitCode === 0) return false;
174+
const failure = classifyAndroidAdbFailure(result.stderr, result.stdout);
175+
return isDeviceOfflineHostRefusal(failure?.reason, failure?.hostRefusal);
176+
}
177+
178+
/** Whether the host adb refused the command for an offline device, as a classified thrown error. */
179+
function isOfflineRefusalError(classified: unknown): boolean {
180+
if (!(classified instanceof AppError)) return false;
181+
return isDeviceOfflineHostRefusal(
182+
classified.details?.adbFailure,
183+
classified.details?.adbHostRefusal,
184+
);
185+
}
186+
174187
/** Whether a classified adb failure is the host adb refusing a command for an offline device. */
175188
function isDeviceOfflineHostRefusal(reason: unknown, hostRefusal: unknown): boolean {
176189
return reason === 'device_offline' && hostRefusal === true;

0 commit comments

Comments
 (0)