1- import type { EnsureReadyInput } from '@agent-device/contracts/device-readiness-runtime' ;
1+ import {
2+ BOOT_TIMEOUT_REASON ,
3+ type EnsureReadyInput ,
4+ } from '@agent-device/contracts/device-readiness-runtime' ;
25import type { PlatformRuntimeHost } from '@agent-device/contracts/platform-runtime-operations' ;
36
47/** Readiness reads exactly these host ports; the lifecycle binding composes the same subset. */
@@ -13,7 +16,6 @@ import { delegateManagedDeviceReadiness } from '@agent-device/provision-kit/mana
1316
1417const BOOT_TIMEOUT_MS = 120_000 ;
1518const POLL_MS = 1_000 ;
16- const BOOT_TIMEOUT_REASON = 'boot_timeout' ;
1719
1820export async function ensureAndroidReady (
1921 host : AndroidReadinessHost ,
@@ -104,11 +106,7 @@ async function waitForDiscovery(
104106 if ( device && isRunningEmulator ( device ) ) return device ;
105107 await host . clock . sleep ( POLL_MS , signal ) ;
106108 }
107- throw new AppError ( 'COMMAND_FAILED' , 'Android emulator did not appear in time' , {
108- avdName,
109- serial,
110- reason : BOOT_TIMEOUT_REASON ,
111- } ) ;
109+ throw bootTimeoutError ( 'Android emulator did not appear in time' , { avdName, serial } ) ;
112110}
113111
114112async function waitForBoot (
@@ -130,8 +128,12 @@ async function waitForBoot(
130128 if ( result . stdout . trim ( ) === '1' ) return ;
131129 await host . clock . sleep ( POLL_MS , signal ) ;
132130 }
133- throw new AppError ( 'COMMAND_FAILED' , 'Android device failed to finish booting' , {
134- serial,
131+ throw bootTimeoutError ( 'Android device failed to finish booting' , { serial } ) ;
132+ }
133+
134+ function bootTimeoutError ( message : string , details : Record < string , unknown > ) : AppError {
135+ return new AppError ( 'COMMAND_FAILED' , message , {
136+ ...details ,
135137 reason : BOOT_TIMEOUT_REASON ,
136138 hint : 'The emulator keeps booting in the background. Retry once it is up, or pass a larger --timeout.' ,
137139 } ) ;
0 commit comments