Skip to content

Commit

Permalink
chore: Replace occurrences of the deprecated errorAndThrow API
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Dec 12, 2024
1 parent 8f66fa6 commit 528b5da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
22 changes: 15 additions & 7 deletions lib/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
}
}

Expand Down Expand Up @@ -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`
);
}
}

Expand Down Expand Up @@ -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}'`);
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions lib/espresso-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`);
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/server-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 528b5da

Please sign in to comment.