Skip to content

Commit

Permalink
chore: Avoid throwing generic error for an unknown execute script name
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Feb 3, 2025
1 parent ceea113 commit 1e7d726
Showing 1 changed file with 8 additions and 8 deletions.
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} `)
: '';
const preprocessedArgs = preprocessExecuteMethodArgs(args);
return await this.executeMethod(formattedScript, [preprocessedArgs]);
}

/**
Expand Down

0 comments on commit 1e7d726

Please sign in to comment.