@@ -774,12 +774,37 @@ function runDevToolsCommand(
774774 shellQuote ( JSON . stringify ( payload ) ) ,
775775 ] . join ( ' ' ) ;
776776
777- return execFileSync ( 'adb' , [ 'shell' , command ] , {
778- encoding : 'utf8' ,
779- timeout : ( timeoutSeconds + 10 ) * 1000 ,
780- } ) ;
777+ try {
778+ return execFileSync ( 'adb' , [ 'shell' , command ] , {
779+ encoding : 'utf8' ,
780+ timeout : ( timeoutSeconds + 10 ) * 1000 ,
781+ } ) ;
782+ } catch ( error ) {
783+ throw new Error ( formatDevToolsCommandError ( method , error ) ) ;
784+ }
781785}
782786
783787function shellQuote ( value : string ) : string {
784788 return `'${ value . replace ( / ' / g, "'\\''" ) } '` ;
785789}
790+
791+ function formatDevToolsCommandError ( method : string , error : unknown ) : string {
792+ if ( ! ( error instanceof Error ) ) {
793+ return `DevTools command '${ method } ' failed: ${ String ( error ) } ` ;
794+ }
795+
796+ const details = error as Error & {
797+ status ?: number ;
798+ signal ?: NodeJS . Signals ;
799+ stdout ?: string | Buffer ;
800+ stderr ?: string | Buffer ;
801+ } ;
802+ const output = [
803+ details . stdout ? `stdout: ${ details . stdout . toString ( ) . trim ( ) } ` : '' ,
804+ details . stderr ? `stderr: ${ details . stderr . toString ( ) . trim ( ) } ` : '' ,
805+ details . status !== undefined ? `status: ${ details . status } ` : '' ,
806+ details . signal ? `signal: ${ details . signal } ` : '' ,
807+ ] . filter ( Boolean ) ;
808+
809+ return [ `DevTools command '${ method } ' failed: ${ error . message } ` , ...output ] . join ( '\n' ) ;
810+ }
0 commit comments