MCPcopy Index your code
hub / github.com/codeaashu/claude-code / execFileNoThrowWithCwd

Function execFileNoThrowWithCwd

src/utils/execFileNoThrow.ts:89–150  ·  view source on GitHub ↗
(
  file: string,
  args: string[],
  {
    abortSignal,
    timeout: finalTimeout = 10 * SECONDS_IN_MINUTE * MS_IN_SECOND,
    preserveOutputOnError: finalPreserveOutput = true,
    cwd: finalCwd,
    env: finalEnv,
    maxBuffer,
    shell,
    stdin: finalStdin,
    input: finalInput,
  }: ExecFileWithCwdOptions = {
    timeout: 10 * SECONDS_IN_MINUTE * MS_IN_SECOND,
    preserveOutputOnError: true,
    maxBuffer: 1_000_000,
  },
)

Source from the content-addressed store, hash-verified

87 * execFile, but always resolves (never throws)
88 */
89export function execFileNoThrowWithCwd(
90 file: string,
91 args: string[],
92 {
93 abortSignal,
94 timeout: finalTimeout = 10 * SECONDS_IN_MINUTE * MS_IN_SECOND,
95 preserveOutputOnError: finalPreserveOutput = true,
96 cwd: finalCwd,
97 env: finalEnv,
98 maxBuffer,
99 shell,
100 stdin: finalStdin,
101 input: finalInput,
102 }: ExecFileWithCwdOptions = {
103 timeout: 10 * SECONDS_IN_MINUTE * MS_IN_SECOND,
104 preserveOutputOnError: true,
105 maxBuffer: 1_000_000,
106 },
107): Promise<{ stdout: string; stderr: string; code: number; error?: string }> {
108 return new Promise(resolve => {
109 // Use execa for cross-platform .bat/.cmd compatibility on Windows
110 execa(file, args, {
111 maxBuffer,
112 signal: abortSignal,
113 timeout: finalTimeout,
114 cwd: finalCwd,
115 env: finalEnv,
116 shell,
117 stdin: finalStdin,
118 input: finalInput,
119 reject: false, // Don't throw on non-zero exit codes
120 })
121 .then(result => {
122 if (result.failed) {
123 if (finalPreserveOutput) {
124 const errorCode = result.exitCode ?? 1
125 void resolve({
126 stdout: result.stdout || '',
127 stderr: result.stderr || '',
128 code: errorCode,
129 error: getErrorMessage(
130 result as unknown as ExecaResultWithError,
131 errorCode,
132 ),
133 })
134 } else {
135 void resolve({ stdout: '', stderr: '', code: result.exitCode ?? 1 })
136 }
137 } else {
138 void resolve({
139 stdout: result.stdout,
140 stderr: result.stderr,
141 code: 0,
142 })
143 }
144 })
145 .catch((error: ExecaError) => {
146 logError(error)

Callers 15

getWorktreePathsFunction · 0.85
fetchSingleFileGitDiffFunction · 0.85
getDiffRefFunction · 0.85
execFileNoThrowFunction · 0.85
copyPngToClipboardFunction · 0.85
getOrCreateWorktreeFunction · 0.85
tearDownFunction · 0.85
copyWorktreeIncludeFilesFunction · 0.85
performPostCreationSetupFunction · 0.85

Calls 3

resolveFunction · 0.70
getErrorMessageFunction · 0.70
logErrorFunction · 0.70

Tested by

no test coverage detected