From 3da19e8603c00c02ec7e24ea8910a7c386b09018 Mon Sep 17 00:00:00 2001 From: syn Date: Fri, 14 Feb 2020 13:09:44 +0300 Subject: Improve error handling --- src/conf.rs | 51 ++------------------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) (limited to 'src/conf.rs') diff --git a/src/conf.rs b/src/conf.rs index febfef5..cc281f0 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1,14 +1,12 @@ use serde_derive::{ Serialize, Deserialize }; use std::path::{ PathBuf, Path }; use toml::de; -use log::{ error, trace }; -use std::io::prelude::*; -use nix::sys::wait::WaitStatus; +use log::{ error }; type Error = std::io::Error; use std::io::ErrorKind; -use crate::backends::{ Backend, PythonBackend, ClangBackend, RunError }; +use crate::backends::{ Backend, PythonBackend, ClangBackend }; #[derive(Debug, Serialize, Deserialize, Default)] @@ -42,51 +40,6 @@ impl Conf { _ => None } } - - pub fn run( - &self, - fname: &Path, - show_time: bool, - show_mem: bool - ) -> Result<(), RunError> { - match self.get_backend(fname) { - Some(backend) => backend.run(fname).map(|info| { - match info.status { - WaitStatus::Exited(_pid, ret) => match ret { - 0 => { - if show_time { - println!("wall time: {:?}", info.wall_time); - } - if show_mem { - println!("rss: {}K", info.usage.ru_maxrss); - } - }, - _ => error!("process exited with {}", ret) - }, - WaitStatus::Signaled(pid, sig, coredump) => { - error!( - "process killed by {} {}. was {}", - sig, - if coredump {"(core dumped)"} else {""}, - pid - ); - }, - _ => error!("process signaled, but not exited") - } - }), - None => Err(Error::new(ErrorKind::InvalidData, "Backend not found").into()) - } - } - - pub fn make(&self, fname: &Path) -> Result<(), RunError> { - trace!("Template: {:?}", self.get_template(&fname)); - - std::fs::File::create(fname)? - .write_all(self.get_template(fname).as_bytes())?; - - trace!("Written some bytes to {}", fname.to_string_lossy()); - Ok(()) - } } -- cgit v1.2.1-18-gbd029