Skip to content

Commit 0f81db7

Browse files
authoredDec 12, 2024··
chore: Replace occurrences of the deprecated errorAndThrow API (#286)
1 parent 4cfd157 commit 0f81db7

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed
 

‎lib/commands/powershell.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ commands.execPowerShell = async function execPowerShell (opts) {
4141
command,
4242
} = opts ?? {};
4343
if (!script && !command) {
44-
this.log.errorAndThrow('Power Shell script/command must not be empty');
44+
throw this.log.errorWithException('Power Shell script/command must not be empty');
4545
}
4646
if (/\n/.test(command ?? '')) {
47-
this.log.errorAndThrow('Power Shell commands cannot contain line breaks');
47+
throw this.log.errorWithException('Power Shell commands cannot contain line breaks');
4848
}
4949
const shouldRunScript = !command && !!script;
5050

‎lib/commands/record-screen.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ async function requireFfmpegPath () {
5252
}
5353

5454
class ScreenRecorder {
55+
/**
56+
* @param {string} videoPath
57+
* @param {import('@appium/types').AppiumLogger} log
58+
* @param {import('@appium/types').StringRecord} opts
59+
*/
5560
constructor (videoPath, log, opts = {}) {
5661
this.log = log;
5762
this._videoPath = videoPath;
@@ -152,8 +157,10 @@ class ScreenRecorder {
152157
});
153158
} catch (e) {
154159
await this._enforceTermination();
155-
this.log.errorAndThrow(`The expected screen record file '${this._videoPath}' does not exist. ` +
156-
`Check the server log for more details`);
160+
throw this.log.errorWithException(
161+
`The expected screen record file '${this._videoPath}' does not exist. ` +
162+
`Check the server log for more details`
163+
);
157164
}
158165
this.log.info(`The video recording has started. Will timeout in ${util.pluralize('second', this._timeLimit, true)}`);
159166
}

‎lib/winappdriver.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class WADProxy extends JWProxy {
2626
/** @type {boolean|undefined} */
2727
didProcessExit;
2828

29+
/**
30+
* @override
31+
*/
2932
async proxyCommand (url, method, body = null) {
3033
if (this.didProcessExit) {
3134
throw new errors.InvalidContextError(
@@ -37,7 +40,12 @@ class WADProxy extends JWProxy {
3740
}
3841

3942
class WADProcess {
40-
constructor (log, opts = {}) {
43+
/**
44+
*
45+
* @param {import('@appium/types').AppiumLogger} log
46+
* @param {{base: string, port: number, executablePath: string, isForceQuitEnabled: boolean}} opts
47+
*/
48+
constructor (log, opts) {
4149
this.log = log;
4250
this.base = opts.base;
4351
this.port = opts.port;
@@ -61,7 +69,7 @@ class WADProcess {
6169
try {
6270
this.port = await findAPortNotInUse(startPort, endPort);
6371
} catch (e) {
64-
this.log.errorAndThrow(
72+
throw this.log.errorWithException(
6573
`Could not find any free port in range ${startPort}..${endPort}. ` +
6674
`Please check your system firewall settings or set 'systemPort' capability ` +
6775
`to the desired port number`);
@@ -116,7 +124,12 @@ process.once('exit', () => {
116124
});
117125

118126
class WinAppDriver {
119-
constructor (log, opts = {}) {
127+
/**
128+
*
129+
* @param {import('@appium/types').AppiumLogger} log
130+
* @param {{port: number}} opts
131+
*/
132+
constructor (log, opts) {
120133
this.log = log;
121134
this.proxyPort = opts.port;
122135

0 commit comments

Comments
 (0)
Please sign in to comment.