[sandbox] Catch broken pipes

This commit is contained in:
orosmatthew 2024-02-17 15:06:49 -05:00
parent 6e673cf390
commit bd1623c09c
4 changed files with 135 additions and 122 deletions

View File

@ -11,7 +11,13 @@ import { runCpp } from './run/cpp.js';
export const timeoutSeconds = 30;
const RunResultKind = z.enum(['CompileFailed', 'TimeLimitExceeded', 'Completed', 'SandboxError', 'RunError']);
const RunResultKind = z.enum([
'CompileFailed',
'TimeLimitExceeded',
'Completed',
'SandboxError',
'RunError'
]);
export type RunResultKind = z.infer<typeof RunResultKind>;
const RunResult = z

View File

@ -4,7 +4,6 @@ import util from 'util';
import { RunResult, timeoutSeconds } from '../index.js';
import { IRunner, IRunnerParams, IRunnerReturn } from './types.js';
import kill from 'tree-kill';
import * as fs from 'fs';
const execPromise = util.promisify(exec);

View File

@ -14,6 +14,7 @@ export const runCSharp: IRunner = async function (params: {
console.log(`- RUN: ${params.srcDir}`);
const child = spawn('dotnet run', { shell: true, cwd: params.srcDir });
try {
let outputBuffer = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
@ -86,4 +87,7 @@ export const runCSharp: IRunner = async function (params: {
}
}
};
} catch (error) {
return { success: false, runResult: { kind: 'RunError' } };
}
};

View File

@ -35,6 +35,7 @@ export const runJava: IRunner<IRunnerParamsJava> = async function (
console.log(`- RUN: ${params.mainClass}`);
const runCommand = `java -cp "${join(params.srcDir, 'build')}" ${params.mainClass}`;
try {
let outputBuffer = '';
const child = spawn(runCommand, { shell: true });
child.stdout.setEncoding('utf8');
@ -104,4 +105,7 @@ export const runJava: IRunner<IRunnerParamsJava> = async function (
}
}
};
} catch (error) {
return { success: false, runResult: { kind: 'RunError' } };
}
};