From 528b5dad23a6dbeb1eab461a88adc05d56373926 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 12 Dec 2024 18:58:43 +0100 Subject: [PATCH] chore: Replace occurrences of the deprecated errorAndThrow API --- lib/driver.ts | 22 +++++++++++++++------- lib/espresso-runner.js | 8 +++++--- lib/server-builder.js | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/driver.ts b/lib/driver.ts index f96cdd6f..557edb81 100644 --- a/lib/driver.ts +++ b/lib/driver.ts @@ -233,8 +233,10 @@ export class EspressoDriver extends AndroidDriver implements ExternalDriver< this.log.warn(`Chrome browser cannot be run in Espresso sessions because Espresso automation doesn't ` + `have permission to access Chrome`); } else { - this.log.errorAndThrow(`Chrome browser sessions cannot be run in Espresso because Espresso ` + - `automation doesn't have permission to access Chrome`); + throw this.log.errorWithException( + `Chrome browser sessions cannot be run in Espresso because Espresso ` + + `automation doesn't have permission to access Chrome` + ); } } @@ -262,8 +264,9 @@ export class EspressoDriver extends AndroidDriver implements ExternalDriver< this.log.info(`App file was not listed, instead we're going to run ` + `${this.opts.appPackage} directly on the device`); if (!await this.adb.isAppInstalled(this.opts.appPackage!)) { - this.log.errorAndThrow(`Could not find the package '${this.opts.appPackage}' ` + - `installed on the device`); + throw this.log.errorWithException( + `Could not find the package '${this.opts.appPackage}' installed on the device` + ); } } @@ -304,8 +307,11 @@ export class EspressoDriver extends AndroidDriver implements ExternalDriver< })).sort((a, b) => a.split(path.sep).length - b.split(path.sep).length); if (sortedBundleItems.length === 0) { // no expected packages in the zip - throw this.log.errorAndThrow(`${this.opts.app} did not have any of '${SUPPORTED_EXTENSIONS.join(', ')}' ` + - `extension packages. Please make sure the provided .zip archive contains at least one valid application package.`); + throw this.log.errorWithException( + `${this.opts.app} did not have any of '${SUPPORTED_EXTENSIONS.join(', ')}' ` + + `extension packages. Please make sure the provided .zip archive contains at ` + + `least one valid application package.` + ); } const unzippedAppPath = path.join(tmpRoot, _.first(sortedBundleItems)!); this.log.debug(`'${unzippedAppPath}' is the unzipped file from '${appPath}'`); @@ -568,7 +574,9 @@ export class EspressoDriver extends AndroidDriver implements ExternalDriver< if (!this.opts.app) { if (this.opts.fullReset) { - this.log.errorAndThrow('Full reset requires an app capability, use fastReset if app is not provided'); + throw this.log.errorWithException( + 'Full reset requires an app capability, use fastReset if app is not provided' + ); } this.log.debug('No app capability. Assuming it is already on the device'); if (this.opts.fastReset) { diff --git a/lib/espresso-runner.js b/lib/espresso-runner.js index 87e211c3..27194849 100644 --- a/lib/espresso-runner.js +++ b/lib/espresso-runner.js @@ -152,7 +152,7 @@ class EspressoRunner { await this.adb.install(this.modServerPath, { replace: false, timeout: this.androidInstallTimeout }); this.log.info(`Installed Espresso Test Server apk '${this.modServerPath}' (pkg: '${TEST_APK_PKG}')`); } catch (err) { - this.log.errorAndThrow(`Cannot install '${this.modServerPath}' because of '${err.message}'`); + throw this.log.errorWithException(`Cannot install '${this.modServerPath}' because of '${err.message}'`); } } } @@ -385,9 +385,11 @@ class EspressoRunner { }); } catch (e) { if (/Condition unmet/.test(e.message)) { - this.log.errorAndThrow(`Timed out waiting for Espresso server to be ` + + throw this.log.errorWithException( + `Timed out waiting for Espresso server to be ` + `online within ${this.serverLaunchTimeout}ms. The timeout value could be ` + - `customized using 'espressoServerLaunchTimeout' capability`); + `customized using 'espressoServerLaunchTimeout' capability` + ); } throw e; } diff --git a/lib/server-builder.js b/lib/server-builder.js index f123a080..5498de96 100644 --- a/lib/server-builder.js +++ b/lib/server-builder.js @@ -191,7 +191,7 @@ class ServerBuilder { } catch (err) { const msg = `Unable to build Espresso server - ${err.message}\n` + `Gradle error message:${EOL}${gradleError.join('\n')}`; - this.log.errorAndThrow(msg); + throw this.log.errorWithException(msg); } finally { gradlebuild.removeAllListeners(); }