@@ -87,7 +87,7 @@ class IOSDeviceLib extends EventEmitter {
87
87
}
88
88
89
89
startDeviceLog ( deviceIdentifiers ) {
90
- this . _getPromise ( MethodNames . log , deviceIdentifiers , { shouldEmit : true , disregardTimeout : true } ) ;
90
+ this . _getPromise ( MethodNames . log , deviceIdentifiers , { shouldEmit : true , disregardTimeout : true , doNotFailOnDeviceLost : true } ) ;
91
91
}
92
92
93
93
connectToPort ( connectToPortArray ) {
@@ -119,12 +119,25 @@ class IOSDeviceLib extends EventEmitter {
119
119
}
120
120
} ;
121
121
122
+ // In case device is lost during waiting for operation to complete
123
+ // or in case we do not execute operation in the specified timeout
124
+ // remove all handlers and reject the promise.
125
+ // NOTE: This is not applicable for device logs, where the Promise is not awaited
126
+ // Rejecting it results in Unhandled Rejection
122
127
const handleMessage = ( message ) => {
123
128
removeListeners ( ) ;
124
129
message . error ? reject ( message . error ) : resolve ( message ) ;
125
130
} ;
126
131
127
- deviceLostHandler = ( device ) => handleMessage ( { error : new Error ( `Device ${ device . deviceId } lost during operation ${ methodName } for message ${ id } ` ) } ) ;
132
+ deviceLostHandler = ( device ) => {
133
+ const message = `Device ${ device . deviceId } lost during operation ${ methodName } for message ${ id } ` ;
134
+
135
+ if ( ! options . doNotFailOnDeviceLost ) {
136
+ message = { error : new Error ( message ) } ;
137
+ }
138
+
139
+ handleMessage ( message ) ;
140
+ } ;
128
141
129
142
eventHandler = ( message ) => {
130
143
if ( message && message . id === id ) {
0 commit comments