[sandbox] Catch broken pipes
This commit is contained in:
parent
6e673cf390
commit
bd1623c09c
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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' } };
|
||||
}
|
||||
};
|
||||
|
@ -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' } };
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user