mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
web: Template time/memory limit errors properly
This commit is contained in:
parent
35ce729f19
commit
fab6238447
2 changed files with 33 additions and 3 deletions
|
@ -8,8 +8,9 @@ use std::os::unix::process::ExitStatusExt;
|
|||
use std::io;
|
||||
use rustc_serialize;
|
||||
use serde_json;
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Rink(QueryError),
|
||||
Time,
|
||||
|
@ -17,6 +18,23 @@ pub enum Error {
|
|||
Generic(String),
|
||||
}
|
||||
|
||||
impl Serialize for Error {
|
||||
fn serialize<S>(
|
||||
&self, ser: &mut S
|
||||
) -> Result<(), S::Error> where S: Serializer {
|
||||
match *self {
|
||||
Error::Rink(ref e) =>
|
||||
ser.serialize_newtype_variant("Error", 0, "Rink", e),
|
||||
Error::Time =>
|
||||
ser.serialize_newtype_variant("Error", 1, "Time", true),
|
||||
Error::Memory =>
|
||||
ser.serialize_newtype_variant("Error", 2, "Memory", true),
|
||||
Error::Generic(ref e) =>
|
||||
ser.serialize_newtype_variant("Error", 3, "Generic", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(err: io::Error) -> Error {
|
||||
Error::Generic(format!("{}", err))
|
||||
|
|
|
@ -245,10 +245,22 @@
|
|||
{{/with}}{{!/Rink}}
|
||||
|
||||
{{!-- Sandbox timed out ----------------------------------}}
|
||||
{{! TODO: Can't be matched on (value, not a key) }}
|
||||
{{#with Time}}
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel-heading">
|
||||
Calculation timed out
|
||||
</div>
|
||||
</div>
|
||||
{{/with}}
|
||||
|
||||
{{!-- Sandbox ran out of memory --------------------------}}
|
||||
{{! TODO: Can't be matched on (value, not a key) }}
|
||||
{{#with Memory}}
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel-heading">
|
||||
Calculation ran out of memory
|
||||
</div>
|
||||
</div>
|
||||
{{/with}}
|
||||
|
||||
{{!-- Generic sandbox errors -----------------------------}}
|
||||
{{#with Generic}}
|
||||
|
|
Loading…
Reference in a new issue