MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / tryDirectCommands

Function tryDirectCommands

src/python/pythonUtils.ts:144–166  ·  view source on GitHub ↗

* Try direct command validation as final fallback.

(commands: string[])

Source from the content-addressed store, hash-verified

142 * Try direct command validation as final fallback.
143 */
144async function tryDirectCommands(commands: string[]): Promise<string | null> {
145 for (const cmd of commands) {
146 try {
147 const validated = await tryPath(cmd);
148 if (validated) {
149 return validated;
150 }
151 } catch (error) {
152 const errorMsg = error instanceof Error ? error.message : String(error);
153 logger.debug(`Direct command "${cmd}" failed: ${errorMsg}`);
154
155 // Log permission/access errors differently
156 if (
157 errorMsg.includes('Access is denied') ||
158 errorMsg.includes('EACCES') ||
159 errorMsg.includes('EPERM')
160 ) {
161 logger.warn(`Permission denied when trying Python command "${cmd}": ${errorMsg}`);
162 }
163 }
164 }
165 return null;
166}
167
168/**
169 * Attempts to get the Python executable path using platform-appropriate strategies.

Callers 1

getSysExecutableFunction · 0.70

Calls 1

tryPathFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…