Skip to content

Commit

Permalink
chore: Replace occurrences of the deprecated errorAndThrow API (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Dec 13, 2024
1 parent f17fbb7 commit 32a5451
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/commands/device/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function getDeviceInfoFromCaps() {
// udid was given, lets try to init with that device
if (udid) {
if (!_.includes(_.map(devices, 'udid'), udid)) {
throw this.log.errorAndThrow(`Device ${udid} was not in the list of connected devices`);
throw this.log.errorWithException(`Device ${udid} was not in the list of connected devices`);
}
emPort = adb.getPortFromEmulatorString(udid);
} else if (this.opts.platformVersion) {
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function getDeviceInfoFromCaps() {

if (!udid) {
// we couldn't find anything! quit
throw this.log.errorAndThrow(
throw this.log.errorWithException(
`Unable to find an active device or emulator ` +
`with OS ${this.opts.platformVersion}. The following are available: ` +
availDevices.join(', '),
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/device/emulator-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ export async function sensorSet(opts) {
requireEmulator.bind(this)('sensorSet is only available for emulators');
const {sensorType, value} = opts;
if (!util.hasValue(sensorType)) {
this.log.errorAndThrow(`'sensorType' argument is required`);
throw this.log.errorWithException(`'sensorType' argument is required`);
}
if (!util.hasValue(value)) {
this.log.errorAndThrow(`'value' argument is required`);
throw this.log.errorWithException(`'value' argument is required`);
}
await this.adb.sensorSet(sensorType, /** @type {any} */ (value));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/device/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const HELPER_APP_INSTALL_RETRY_DELAY_MS = 5000;
*/
export function requireEmulator(errMsg) {
if (!this.isEmulator()) {
this.log.errorAndThrow(errMsg);
throw this.log.errorWithException(errMsg);
}
}

Expand Down
14 changes: 7 additions & 7 deletions lib/commands/file-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function pullFile(remotePath) {
`cp -f '${escapePath(pathInContainer)}' '${escapePath(tmpDestination)}'`,
]);
} catch (e) {
this.log.errorAndThrow(
throw this.log.errorWithException(
`Cannot access the container of '${packageId}' application. ` +
`Is the application installed and has 'debuggable' build option set to true? ` +
`Original error: ${/** @type {Error} */ (e).message}`,
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function pushFile(remotePath, base64Data) {
`cp -f '${escapePath(tmpDestination)}' '${escapePath(pathInContainer)}'`,
]);
} catch (e) {
this.log.errorAndThrow(
throw this.log.errorWithException(
`Cannot access the container of '${packageId}' application. ` +
`Is the application installed and has 'debuggable' build option set to true? ` +
`Original error: ${/** @type {Error} */ (e).message}`,
Expand Down Expand Up @@ -220,7 +220,7 @@ async function deleteFileOrFolder(adb, remotePath) {
try {
await adb.shell(['run-as', pkgId, 'ls']);
} catch (e) {
this.log.errorAndThrow(
throw this.log.errorWithException(
`Cannot access the container of '${pkgId}' application. ` +
`Is the application installed and has 'debuggable' build option set to true? ` +
`Original error: ${/** @type {Error} */ (e).message}`,
Expand All @@ -235,9 +235,9 @@ async function deleteFileOrFolder(adb, remotePath) {

const expectsFile = !remotePath.endsWith('/');
if (expectsFile && !(await isFile(dstPath, pkgId))) {
this.log.errorAndThrow(`The item at '${dstPath}' is not a file`);
throw this.log.errorWithException(`The item at '${dstPath}' is not a file`);
} else if (!expectsFile && !(await isDir(dstPath, pkgId))) {
this.log.errorAndThrow(`The item at '${dstPath}' is not a folder`);
throw this.log.errorWithException(`The item at '${dstPath}' is not a folder`);
}

if (pkgId) {
Expand All @@ -246,8 +246,8 @@ async function deleteFileOrFolder(adb, remotePath) {
await adb.shell(['rm', `-f${expectsFile ? '' : 'r'}`, dstPath]);
}
if (await isPresent(dstPath, pkgId)) {
this.log.errorAndThrow(
`The item at '${dstPath}' still exists after being deleted. ` + `Is it writable?`,
throw this.log.errorWithException(
`The item at '${dstPath}' still exists after being deleted. Is it writable?`,
);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function getDisplayDensity() {
this.log.debug(`Parsed density value was NaN: "${out}"`);
}
// couldn't get anything, so error out
throw this.log.errorAndThrow('Failed to get display density property.');
throw this.log.errorWithException('Failed to get display density property.');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/recordscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ export async function stopRecordingScreen(options = {}) {
PROCESS_SHUTDOWN_TIMEOUT,
);
} catch (e) {
this.log.errorAndThrow(
throw this.log.errorWithException(
`Unable to stop screen recording within ${PROCESS_SHUTDOWN_TIMEOUT}ms`,
);
}
this._screenRecordingProperties.recordingProcess = null;
}

if (_.isEmpty(this._screenRecordingProperties.records)) {
this.log.errorAndThrow(
throw this.log.errorWithException(
`No screen recordings have been stored on the device so far. ` +
`Are you sure the ${SCREENRECORD_BINARY} utility works as expected?`,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function mobileShell(opts) {
return stdout;
} catch (e) {
const err = /** @type {import('teen_process').ExecError} */ (e);
throw this.log.errorAndThrow(
throw this.log.errorWithException(
`Cannot execute the '${command}' shell command. ` +
`Original error: ${err.message}. ` +
`StdOut: ${err.stdout}. StdErr: ${err.stderr}`,
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/streamscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function mobileStartScreenStreaming(options = {}) {
return;
}
if ((await checkPortStatus(tcpPort, TCP_HOST)) === 'open') {
this.log.errorAndThrow(
throw this.log.errorWithException(
`The port #${tcpPort} at ${TCP_HOST} is busy. ` +
`Make sure there are no leftovers from previous sessions.`,
);
Expand Down Expand Up @@ -389,7 +389,7 @@ async function initDeviceStreamingProc(adb, log, deviceInfo, opts = {}) {
intervalMs: 300,
});
} catch (e) {
log.errorAndThrow(
throw log.errorWithException(
`Cannot start the screen streaming process. Original error: ${
/** @type {Error} */ (e).message
}`,
Expand Down Expand Up @@ -483,7 +483,7 @@ async function initGstreamerPipeline(deviceStreamingProc, deviceInfo, log, opts)
);
} catch (e) {
didFail = true;
log.errorAndThrow(
throw log.errorWithException(
`Cannot start the screen streaming pipeline. Original error: ${
/** @type {Error} */ (e).message
}`,
Expand Down
4 changes: 2 additions & 2 deletions lib/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class AndroidDriver
);
}
if (caps.appPackage) {
throw this.log.errorAndThrow(
throw this.log.errorWithException(
`The desired should not include both of an 'appPackage' and a 'browserName'`,
);
}
Expand All @@ -326,7 +326,7 @@ class AndroidDriver
try {
parseArray(caps.uninstallOtherPackages);
} catch (e) {
throw this.log.errorAndThrow(
throw this.log.errorWithException(
`Could not parse "uninstallOtherPackages" capability: ${(e as Error).message}`,
);
}
Expand Down

0 comments on commit 32a5451

Please sign in to comment.