Skip to content

Commit 04ffe3b

Browse files
Fix processRunner exports, runtimeEnvironment leak, and null exit code message
- Remove unnecessary exports from processRunner.ts: toRuntimeCommandOptions, ManagedChildProcess, RuntimeCommandOptions, spawnPipedProcess, ProcessSpawnOptions, ProcessSpawnSyncOptions, killProcessTree - Destructure runtimeEnvironment out of options in toRuntimeCommandOptions to prevent leaking it into ChildProcess.make - Handle null exit code in detailFromResult to produce a clear message instead of 'Command exited with code null' Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
1 parent df5009c commit 04ffe3b

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

apps/server/src/processRunner.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ interface RuntimeShellOptions {
2424
shell?: boolean | string | undefined;
2525
}
2626

27-
export interface ProcessSpawnOptions extends ProcessSpawnBaseOptions {
27+
interface ProcessSpawnOptions extends ProcessSpawnBaseOptions {
2828
stdio?: StdioOptions | undefined;
2929
detached?: boolean | undefined;
3030
}
3131

32-
export interface RuntimeCommandOptions extends ChildProcess.CommandOptions {
32+
interface RuntimeCommandOptions extends ChildProcess.CommandOptions {
3333
runtimeEnvironment?: ServerRuntimeEnvironment | undefined;
3434
}
3535

36-
export interface ProcessSpawnSyncOptions extends ProcessSpawnBaseOptions {
36+
interface ProcessSpawnSyncOptions extends ProcessSpawnBaseOptions {
3737
stdio?: StdioOptions | undefined;
3838
detached?: boolean | undefined;
3939
encoding?: BufferEncoding | undefined;
@@ -90,11 +90,12 @@ function toSpawnOptions(options: ProcessSpawnOptions) {
9090
};
9191
}
9292

93-
export function toRuntimeCommandOptions(
93+
function toRuntimeCommandOptions(
9494
options: RuntimeCommandOptions = {},
9595
): ChildProcess.CommandOptions {
96+
const { runtimeEnvironment: _, ...rest } = options;
9697
return {
97-
...options,
98+
...rest,
9899
shell: options.shell ?? shouldUseShell(options),
99100
};
100101
}
@@ -107,7 +108,7 @@ export function makeRuntimeCommand(
107108
return ChildProcess.make(command, [...args], toRuntimeCommandOptions(options));
108109
}
109110

110-
export interface ManagedChildProcess {
111+
interface ManagedChildProcess {
111112
readonly scope: Scope.Closeable;
112113
readonly handle: ChildProcessSpawner.ChildProcessHandle;
113114
}
@@ -135,7 +136,7 @@ function spawnProcess(
135136
return spawn(command, args, toSpawnOptions(options));
136137
}
137138

138-
export function spawnPipedProcess(
139+
function spawnPipedProcess(
139140
command: string,
140141
args: readonly string[],
141142
options: Omit<ProcessSpawnOptions, "stdio" | "detached"> = {},
@@ -252,7 +253,7 @@ const DEFAULT_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
252253
* wrapper, leaving the actual command running. Use `taskkill /T` to kill the
253254
* entire process tree instead.
254255
*/
255-
export function killProcessTree(
256+
function killProcessTree(
256257
child: ChildProcessHandle,
257258
options: {
258259
runtimeEnvironment?: ServerRuntimeEnvironment | undefined;

apps/server/src/provider/Layers/ProviderHealth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ function detailFromResult(
7676
if (stderr) return stderr;
7777
const stdout = nonEmptyTrimmed(result.stdout);
7878
if (stdout) return stdout;
79+
if (result.code === null) {
80+
return "Command was terminated before reporting an exit code.";
81+
}
7982
if (result.code !== 0) {
8083
return `Command exited with code ${result.code}.`;
8184
}

0 commit comments

Comments
 (0)