Properly handle input/output errors

This commit is contained in:
Patrick Lühne 2020-05-19 13:10:31 +02:00
parent efe354faad
commit b62c379b97
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 42 additions and 18 deletions

View File

@ -30,6 +30,7 @@ pub enum Kind
// TODO: rename to something Vampire-specific
ProveProgram(Option<i32>, String, String),
ParseVampireOutput(String, String),
IO,
}
pub struct Error
@ -191,6 +192,11 @@ impl Error
{
Self::new(Kind::ParseVampireOutput(stdout, stderr))
}
pub(crate) fn new_io<S: Into<Source>>(source: S) -> Self
{
Self::new(Kind::IO).with(source)
}
}
impl std::fmt::Debug for Error
@ -275,6 +281,7 @@ impl std::fmt::Debug for Error
{}\
==== stderr ===========================================================\n\
{}", stdout, stderr),
Kind::IO => write!(formatter, "input/output error"),
}?;
if let Some(source) = &self.source
@ -305,3 +312,11 @@ impl std::error::Error for Error
}
}
}
impl From<std::io::Error> for Error
{
fn from(error: std::io::Error) -> Self
{
Self::new_io(error)
}
}

View File

@ -190,13 +190,16 @@ impl Problem
}
fn print_step_title(&self, step_title: &str, color: &termcolor::ColorSpec)
-> Result<(), crate::Error>
{
let longest_possible_key = " Finished";
self.shell.borrow_mut().print(
&format!("{:>step_title_width$} ", step_title,
step_title_width = longest_possible_key.chars().count()),
color);
color)?;
Ok(())
}
pub fn prove(&self, proof_direction: ProofDirection) -> Result<(), crate::Error>
@ -205,9 +208,9 @@ impl Problem
|| proof_direction == ProofDirection::Both
{
self.print_step_title("Started",
termcolor::ColorSpec::new().set_bold(true).set_fg(Some(termcolor::Color::Green)));
termcolor::ColorSpec::new().set_bold(true).set_fg(Some(termcolor::Color::Green)))?;
self.shell.borrow_mut().println(&"verification of assertions from translated program",
&termcolor::ColorSpec::new());
&termcolor::ColorSpec::new())?;
let mut statements = self.statements.borrow_mut();
@ -244,7 +247,7 @@ impl Problem
ProofResult::Disproven => step_title_color.set_fg(Some(termcolor::Color::Red)),
};
self.print_step_title("Finished", &step_title_color);
self.print_step_title("Finished", &step_title_color)?;
println!("verification of assertions from translated program");
}
@ -257,9 +260,9 @@ impl Problem
|| proof_direction == ProofDirection::Both
{
self.print_step_title("Started",
termcolor::ColorSpec::new().set_bold(true).set_fg(Some(termcolor::Color::Green)));
termcolor::ColorSpec::new().set_bold(true).set_fg(Some(termcolor::Color::Green)))?;
self.shell.borrow_mut().println(&"verification of translated program from assertions",
&termcolor::ColorSpec::new());
&termcolor::ColorSpec::new())?;
let mut statements = self.statements.borrow_mut();
@ -295,7 +298,7 @@ impl Problem
ProofResult::Disproven => step_title_color.set_fg(Some(termcolor::Color::Red)),
};
self.print_step_title("Finished", &step_title_color);
self.print_step_title("Finished", &step_title_color)?;
println!("verification of translated program from assertions");
}
@ -324,7 +327,7 @@ impl Problem
fn prove_unproven_statements(&self) -> Result<ProofResult, crate::Error>
{
let display_statement = |statement: &Statement|
let display_statement = |statement: &Statement| -> Result<(), crate::Error>
{
let step_title = match statement.proof_status
{
@ -349,10 +352,10 @@ impl Problem
_ => step_title_color.set_fg(Some(termcolor::Color::Cyan)),
};
self.print_step_title(&step_title, &step_title_color);
self.print_step_title(&step_title, &step_title_color)?;
self.shell.borrow_mut().print(&format!("{}: ", statement.kind),
&termcolor::ColorSpec::new());
&termcolor::ColorSpec::new())?;
let format_context = FormatContext
{
@ -365,6 +368,8 @@ impl Problem
};
print!("{}", foliage::format::display_formula(&statement.formula, &format_context));
Ok(())
};
// Show all statements that are assumed to be proven
@ -373,7 +378,7 @@ impl Problem
for statement in statements.iter_mut()
.filter(|statement| statement.proof_status == ProofStatus::AssumedProven)
{
display_statement(statement);
display_statement(statement)?;
println!("");
}
}
@ -381,16 +386,18 @@ impl Problem
loop
{
match self.next_unproven_statement_do_mut(
|statement|
|statement| -> Result<(), crate::Error>
{
statement.proof_status = ProofStatus::ToProveNow;
print!("\x1b[s");
display_statement(statement);
display_statement(statement)?;
print!("\x1b[u");
use std::io::Write as _;
std::io::stdout().flush();
std::io::stdout().flush()?;
Ok(())
})
{
Some(_) => (),
@ -412,7 +419,7 @@ impl Problem
Some(&["--mode", "casc", "--cores", "8", "--time_limit", "300"]))?;
match self.next_unproven_statement_do_mut(
|statement|
|statement| -> Result<(), crate::Error>
{
statement.proof_status = match proof_result
{
@ -423,7 +430,7 @@ impl Problem
self.shell.borrow_mut().erase_line();
display_statement(statement);
display_statement(statement)?;
match proof_result
{
@ -435,15 +442,17 @@ impl Problem
if let Some(proof_time_seconds) = proof_time_seconds
{
self.shell.borrow_mut().print(&format!(" in {} seconds", proof_time_seconds),
termcolor::ColorSpec::new().set_fg(Some(termcolor::Color::Black)).set_intense(true));
termcolor::ColorSpec::new().set_fg(Some(termcolor::Color::Black)).set_intense(true))?;
}
Ok(())
})
{
Some(_) => (),
None => unreachable!(),
}
self.shell.borrow_mut().println(&"", &termcolor::ColorSpec::new());
self.shell.borrow_mut().println(&"", &termcolor::ColorSpec::new())?;
if proof_result != ProofResult::Proven
{