Skip to content

Commit

Permalink
[add] add message for RuntimeError
Browse files Browse the repository at this point in the history
  • Loading branch information
baka233 committed May 16, 2021
1 parent e31ac97 commit d1c3412
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/judge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fs::File;
use std::io;
use std::io::Read;
use std::os::unix::fs as unix_fs;
use std::process::{Command, Stdio};
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -165,7 +166,10 @@ pub async fn judge(
real_time,
}
};
log::debug!("Generate the process report of {}", runtime_dir.display());
let stderr = child.stderr();
log::debug!("Generate the process report of {}, {:?}", runtime_dir.display(), &resource_usage);

let mut message = String::new();

let result_type = if resource_usage.memory >= problem_dir.config().limit.memory {
ResultType::MemoryLimitExceeded
Expand All @@ -174,6 +178,11 @@ pub async fn judge(
{
ResultType::TimeLimitExceeded
} else if !exit_status.success() {
let mut buffer = vec![0; 1024];
if let Some(out) = stderr {
out.read(buffer.as_mut());
message = String::from_utf8_lossy(buffer.as_slice()).to_string();
}
ResultType::RuntimeError
} else if Comparer::new(
problem_dir
Expand All @@ -196,7 +205,7 @@ pub async fn judge(
let res = Report {
result: result_type,
usage: Some(resource_usage),
message: String::new(),
message,
};
if reporter.send(res).is_err() {
return Err(broken_channel());
Expand Down Expand Up @@ -265,8 +274,7 @@ pub async fn judge(
real_time,
}
};
log::debug!("Generate the process report of {}, 为啥啊", runtime_dir.display());
dbg!(&resource_usage);
log::debug!("Generate the process report of {}", runtime_dir.display());

let result_type = if resource_usage.memory >= problem_dir.config().limit.memory {
ResultType::MemoryLimitExceeded
Expand Down
6 changes: 5 additions & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::OsString;
use std::io;
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
use std::process::{Child, Command, Stdio, ChildStderr};
use std::time::Duration;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -120,6 +120,10 @@ impl Program {
);
Ok(res)
}

pub fn stderr(&mut self) -> Option<&mut ChildStderr> {
self.inner.stderr.as_mut()
}
}

impl Drop for Program {
Expand Down

0 comments on commit d1c3412

Please sign in to comment.