diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index fcfe5d444..ad7cca27e 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.14.10", + "version": "2.15.0", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index c102ea5a7..72ba2154d 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -82,6 +82,22 @@ function judgeCase(c: Case, sid: string) { } else if (status === STATUS.STATUS_RUNTIME_ERROR && code) { if (code < 32) message = signals[code]; else message = { message: 'Your program returned {0}.', params: [code] }; + const langConfig = ctx.getLang(ctx.lang); + if (langConfig.runtimeErrorAnalysis && !this.runtimeErrorAnalysis) { + this.runtimeErrorAnalysis = true; + run(langConfig.runtimeErrorAnalysis, { + copyIn: { + input: { src: stdin }, + [langConfig.code_file || 'foo']: { content: ctx.code }, + compile: { content: langConfig.compile }, + execute: { content: langConfig.execute }, + }, + time: 5000, + memory: 256, + }) + .then((r) => ctx.next({ compiler_text: r.stdout.toString().substring(0, 1024) })) + .catch((e) => console.error(e)); + } } await Promise.all( Object.values(res.fileIds).map((id) => del(id)), diff --git a/packages/hydrojudge/src/judge/interface.ts b/packages/hydrojudge/src/judge/interface.ts index 5c8980db4..7e59af7bc 100644 --- a/packages/hydrojudge/src/judge/interface.ts +++ b/packages/hydrojudge/src/judge/interface.ts @@ -6,6 +6,7 @@ export type Context = JudgeTaskInterface & RuntimeContext; export interface JudgeTaskInterface { next(arg0: { + compiler_text?: string; status?: number; message?: string; progress?: number; diff --git a/packages/hydrojudge/src/judge/run.ts b/packages/hydrojudge/src/judge/run.ts index bc3f1c591..0afcd9959 100644 --- a/packages/hydrojudge/src/judge/run.ts +++ b/packages/hydrojudge/src/judge/run.ts @@ -79,6 +79,21 @@ export const judge = async (ctx: Context) => { status = STATUS.STATUS_RUNTIME_ERROR; if (code < 32) message.push(`ExitCode: ${code} (${signals[code]})`); else message.push(`ExitCode: ${code}`); + const langConfig = ctx.getLang(ctx.lang); + if (langConfig.runtimeErrorAnalysis) { + run(langConfig.runtimeErrorAnalysis, { + copyIn: { + input: { src: stdin }, + [langConfig.code_file || 'foo']: { content: ctx.code }, + compile: { content: langConfig.compile }, + execute: { content: langConfig.execute }, + }, + time: 5000, + memory: 256, + }) + .then((r) => ctx.next({ compiler_text: r.stdout.toString().substring(0, 1024) })) + .catch((e) => console.error(e)); + } } message.push(fs.readFileSync(stdout).toString()); message.push(fs.readFileSync(stderr).toString()); diff --git a/packages/utils/lib/lang.ts b/packages/utils/lib/lang.ts index 871473688..ade7143c3 100644 --- a/packages/utils/lib/lang.ts +++ b/packages/utils/lib/lang.ts @@ -12,6 +12,7 @@ export interface LangConfig { target?: string; key: string; hidden: boolean; + runtimeErrorAnalysis?: string; } export function parseLang(config: string): Record {