Skip to content

Commit 2bf6d52

Browse files
Merge pull request #40 from telerik/vladimirov/fix-unhandled-rejection
fix: Unhandled Rejection is thrown from device logs
2 parents a0c256d + 14bd510 commit 2bf6d52

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class IOSDeviceLib extends EventEmitter {
8787
}
8888

8989
startDeviceLog(deviceIdentifiers) {
90-
this._getPromise(MethodNames.log, deviceIdentifiers, { shouldEmit: true, disregardTimeout: true });
90+
this._getPromise(MethodNames.log, deviceIdentifiers, { shouldEmit: true, disregardTimeout: true, doNotFailOnDeviceLost: true });
9191
}
9292

9393
connectToPort(connectToPortArray) {
@@ -119,12 +119,25 @@ class IOSDeviceLib extends EventEmitter {
119119
}
120120
};
121121

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
122127
const handleMessage = (message) => {
123128
removeListeners();
124129
message.error ? reject(message.error) : resolve(message);
125130
};
126131

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+
};
128141

129142
eventHandler = (message) => {
130143
if (message && message.id === id) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ios-device-lib",
3-
"version": "0.4.11",
3+
"version": "0.4.12",
44
"description": "",
55
"types": "./typings/ios-device-lib.d.ts",
66
"main": "index.js",

0 commit comments

Comments
 (0)