@@ -736,12 +736,37 @@ function runDevToolsCommand(
736736 shellQuote ( JSON . stringify ( payload ) ) ,
737737 ] . join ( ' ' ) ;
738738
739- return execFileSync ( 'adb' , [ 'shell' , command ] , {
740- encoding : 'utf8' ,
741- timeout : ( timeoutSeconds + 10 ) * 1000 ,
742- } ) ;
739+ try {
740+ return execFileSync ( 'adb' , [ 'shell' , command ] , {
741+ encoding : 'utf8' ,
742+ timeout : ( timeoutSeconds + 10 ) * 1000 ,
743+ } ) ;
744+ } catch ( error ) {
745+ throw new Error ( formatDevToolsCommandError ( method , error ) ) ;
746+ }
743747}
744748
745749function shellQuote ( value : string ) : string {
746750 return `'${ value . replace ( / ' / g, "'\\''" ) } '` ;
747751}
752+
753+ function formatDevToolsCommandError ( method : string , error : unknown ) : string {
754+ if ( ! ( error instanceof Error ) ) {
755+ return `DevTools command '${ method } ' failed: ${ String ( error ) } ` ;
756+ }
757+
758+ const details = error as Error & {
759+ status ?: number ;
760+ signal ?: NodeJS . Signals ;
761+ stdout ?: string | Buffer ;
762+ stderr ?: string | Buffer ;
763+ } ;
764+ const output = [
765+ details . stdout ? `stdout: ${ details . stdout . toString ( ) . trim ( ) } ` : '' ,
766+ details . stderr ? `stderr: ${ details . stderr . toString ( ) . trim ( ) } ` : '' ,
767+ details . status !== undefined ? `status: ${ details . status } ` : '' ,
768+ details . signal ? `signal: ${ details . signal } ` : '' ,
769+ ] . filter ( Boolean ) ;
770+
771+ return [ `DevTools command '${ method } ' failed: ${ error . message } ` , ...output ] . join ( '\n' ) ;
772+ }
0 commit comments