From 4e2937fc614538fd73363a41667c9472fb6ff5f3 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 27 Dec 2016 20:58:51 +0100 Subject: refactor error handling with error_chain --- src/transpile_js.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/transpile_js.rs') diff --git a/src/transpile_js.rs b/src/transpile_js.rs index 5ca16e6..269e900 100644 --- a/src/transpile_js.rs +++ b/src/transpile_js.rs @@ -2,14 +2,15 @@ extern crate modelica_parser; use self::modelica_parser::*; +use errors::Result; pub trait TranspileJS { - fn repr_js(&self) -> Result; + fn repr_js(&self) -> Result; } impl TranspileJS for ModelicaModel { - fn repr_js(&self) -> Result { + fn repr_js(&self) -> Result { let mut constants = vec![]; for (c, e) in self.get_constant_vars() { if let Some(v) = e { @@ -23,8 +24,7 @@ impl TranspileJS for ModelicaModel { binds.push(format!("var {} = {};", symb, try!(eq.rhs.repr_js()))); outputs.push(symb.to_string()); } else { - return Err("Expected an identifier on LHS (in this partial implementation)" - .to_string()); + bail!("Expected an identifier on LHS (in this partial implementation)") } } let args: Vec = self.get_free_vars().iter().map(|s| s.clone()).collect(); @@ -42,7 +42,7 @@ impl TranspileJS for ModelicaModel { } impl TranspileJS for Expr { - fn repr_js(&self) -> Result { + fn repr_js(&self) -> Result { use modelica_parser::Expr::*; match *self { Integer(e) => Ok(format!("{}", e)), @@ -57,7 +57,7 @@ impl TranspileJS for Expr { BinExpr(op, ref l, ref r) => { Ok(format!("({} {:?} {})", try!(l.repr_js()), op, try!(r.repr_js()))) } - Array(_) => Err("Array unimplemented".to_string()), + Array(_) => bail!("Array unimplemented"), } } } -- cgit v1.2.3