Skip to content

Commit

Permalink
chore: Replace occurrences of the deprecated errorAndThrow API (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Dec 12, 2024
1 parent 4cfd157 commit 0f81db7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/commands/powershell.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ commands.execPowerShell = async function execPowerShell (opts) {
command,
} = opts ?? {};
if (!script && !command) {
this.log.errorAndThrow('Power Shell script/command must not be empty');
throw this.log.errorWithException('Power Shell script/command must not be empty');
}
if (/\n/.test(command ?? '')) {
this.log.errorAndThrow('Power Shell commands cannot contain line breaks');
throw this.log.errorWithException('Power Shell commands cannot contain line breaks');
}
const shouldRunScript = !command && !!script;

Expand Down
11 changes: 9 additions & 2 deletions lib/commands/record-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ async function requireFfmpegPath () {
}

class ScreenRecorder {
/**
* @param {string} videoPath
* @param {import('@appium/types').AppiumLogger} log
* @param {import('@appium/types').StringRecord} opts
*/
constructor (videoPath, log, opts = {}) {
this.log = log;
this._videoPath = videoPath;
Expand Down Expand Up @@ -152,8 +157,10 @@ class ScreenRecorder {
});
} catch (e) {
await this._enforceTermination();
this.log.errorAndThrow(`The expected screen record file '${this._videoPath}' does not exist. ` +
`Check the server log for more details`);
throw this.log.errorWithException(
`The expected screen record file '${this._videoPath}' does not exist. ` +
`Check the server log for more details`
);
}
this.log.info(`The video recording has started. Will timeout in ${util.pluralize('second', this._timeLimit, true)}`);
}
Expand Down
19 changes: 16 additions & 3 deletions lib/winappdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class WADProxy extends JWProxy {
/** @type {boolean|undefined} */
didProcessExit;

/**
* @override
*/
async proxyCommand (url, method, body = null) {
if (this.didProcessExit) {
throw new errors.InvalidContextError(
Expand All @@ -37,7 +40,12 @@ class WADProxy extends JWProxy {
}

class WADProcess {
constructor (log, opts = {}) {
/**
*
* @param {import('@appium/types').AppiumLogger} log
* @param {{base: string, port: number, executablePath: string, isForceQuitEnabled: boolean}} opts
*/
constructor (log, opts) {
this.log = log;
this.base = opts.base;
this.port = opts.port;
Expand All @@ -61,7 +69,7 @@ class WADProcess {
try {
this.port = await findAPortNotInUse(startPort, endPort);
} catch (e) {
this.log.errorAndThrow(
throw this.log.errorWithException(
`Could not find any free port in range ${startPort}..${endPort}. ` +
`Please check your system firewall settings or set 'systemPort' capability ` +
`to the desired port number`);
Expand Down Expand Up @@ -116,7 +124,12 @@ process.once('exit', () => {
});

class WinAppDriver {
constructor (log, opts = {}) {
/**
*
* @param {import('@appium/types').AppiumLogger} log
* @param {{port: number}} opts
*/
constructor (log, opts) {
this.log = log;
this.proxyPort = opts.port;

Expand Down

0 comments on commit 0f81db7

Please sign in to comment.