Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Avoid throwing generic error for an unknown execute script name #291

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/commands/execute.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash';
import { errors } from 'appium/driver';
import { POWER_SHELL_FEATURE } from '../constants';

const POWER_SHELL_SCRIPT = 'powerShell';
Expand All @@ -13,18 +12,19 @@ const EXECUTE_SCRIPT_PREFIX = 'windows:';
* @returns {Promise<any>}
*/
export async function execute (script, args) {
if (_.startsWith(script, EXECUTE_SCRIPT_PREFIX)) {
this.log.info(`Executing extension command '${script}'`);
const formattedScript = script.trim().replace(/^windows:\s*/, `${EXECUTE_SCRIPT_PREFIX} `);
const preprocessedArgs = preprocessExecuteMethodArgs(args);
return await this.executeMethod(formattedScript, [preprocessedArgs]);
} else if (script === POWER_SHELL_SCRIPT) {
if (script === POWER_SHELL_SCRIPT) {
this.assertFeatureEnabled(POWER_SHELL_FEATURE);
return await this.execPowerShell(
/** @type {import('./powershell').ExecPowerShellOptions} */ (preprocessExecuteMethodArgs(args))
);
}
throw new errors.NotImplementedError();

this.log.info(`Executing extension command '${script}'`);
const formattedScript = _.isString(script)
? script.trim().replace(/^windows:\s*/, `${EXECUTE_SCRIPT_PREFIX} `)
: String(script);
const preprocessedArgs = preprocessExecuteMethodArgs(args);
return await this.executeMethod(formattedScript, [preprocessedArgs]);
}

/**
Expand Down