BUGFIX: Error message for parse errors reported wrong file name.

This commit is contained in:
Jeremy Wall 2018-08-15 18:37:31 -05:00
parent 6418533562
commit ca982dfc02
2 changed files with 11 additions and 5 deletions

View File

@ -41,4 +41,4 @@ let server_config = {
l = ["foo", "bar"] l = ["foo", "bar"]
}; };
out json server_config; out "json" server_config;

View File

@ -298,8 +298,9 @@ pub struct AssertCollector {
} }
/// Builder handles building ucg code for a single file.. /// Builder handles building ucg code for a single file..
pub struct Builder { pub struct Builder<'a> {
root: PathBuf, root: PathBuf,
curr_file: Option<&'a str>,
validate_mode: bool, validate_mode: bool,
assert_collector: AssertCollector, assert_collector: AssertCollector,
env: Rc<Val>, env: Rc<Val>,
@ -339,7 +340,7 @@ macro_rules! eval_binary_expr {
}; };
} }
impl Builder { impl<'a> Builder<'a> {
// TOOD(jwall): This needs some unit tests. // TOOD(jwall): This needs some unit tests.
fn tuple_to_val(&self, fields: &Vec<(Token, Expression)>) -> Result<Rc<Val>, Box<Error>> { fn tuple_to_val(&self, fields: &Vec<(Token, Expression)>) -> Result<Rc<Val>, Box<Error>> {
let mut new_fields = Vec::<(Positioned<String>, Rc<Val>)>::new(); let mut new_fields = Vec::<(Positioned<String>, Rc<Val>)>::new();
@ -409,6 +410,7 @@ impl Builder {
) -> Self { ) -> Self {
Builder { Builder {
root: root.into(), root: root.into(),
curr_file: None,
validate_mode: false, validate_mode: false,
assert_collector: AssertCollector { assert_collector: AssertCollector {
success: true, success: true,
@ -463,7 +465,10 @@ impl Builder {
} }
} }
Err(err) => Err(Box::new(error::Error::new_with_cause( Err(err) => Err(Box::new(error::Error::new_with_cause(
format!("Error while parsing file: {}", self.root.to_string_lossy()), format!(
"Error while parsing file: {}",
self.curr_file.unwrap_or("<eval>")
),
error::ErrorType::ParseError, error::ErrorType::ParseError,
err, err,
))), ))),
@ -471,8 +476,9 @@ impl Builder {
} }
/// Builds a ucg file at the named path. /// Builds a ucg file at the named path.
pub fn build_file(&mut self, name: &str) -> BuildResult { pub fn build_file(&mut self, name: &'a str) -> BuildResult {
eprintln!("building ucg file {}", name); eprintln!("building ucg file {}", name);
self.curr_file = Some(name);
let mut f = try!(File::open(name)); let mut f = try!(File::open(name));
let mut s = String::new(); let mut s = String::new();
try!(f.read_to_string(&mut s)); try!(f.read_to_string(&mut s));