chore: Make attachUnexpectedShutdownHandler method more forgivable
MODIFY
lib/appium.js
lib/appium.js
@@ -409,7 +409,8 @@ class AppiumDriver extends BaseDriver {
delete this.sessions[innerSessionId];
};
- if (_.has(driver.onUnexpectedShutdown, 'then')) {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ if (_.isFunction((driver.onUnexpectedShutdown || {}).then)) {
// TODO: Remove this block after all the drivers use base driver above v 5.0.0
// Remove the session on unexpected shutdown, so that we are in a position
// to open another session later on.
@@ -426,9 +427,12 @@ class AppiumDriver extends BaseDriver {
removeSessionFromMasterList(e);
}
}); // this is a cancellable promise
- } else {
+ } else if (_.isFunction(driver.onUnexpectedShutdown)) {
// since base driver v 5.0.0
driver.onUnexpectedShutdown(removeSessionFromMasterList);
+ } else {
+ log.warn(`Failed to attach the unexpected shutdown listener. ` +
+ `Is 'onUnexpectedShutdown' method available for '${driver.constructor.name}'?`);
}
}

chore: Make attachUnexpectedShutdownHandler method more forgivable (#13662)