FEATURE: Wrap include failures in a Build Error.

This is way more ergonomic for the users.
This commit is contained in:
Jeremy Wall 2019-02-20 20:29:32 -06:00
parent 014710a4ba
commit 1699801895
3 changed files with 21 additions and 3 deletions

View File

@ -1658,8 +1658,20 @@ impl<'a> FileBuilder<'a> {
eprintln!("including an empty file. Use NULL as the result");
Rc::new(Val::Empty)
} else {
// FIXME(jwall): This should be wrapped in a BuildError
importer.import(file_contents.as_bytes())?
match importer.import(file_contents.as_bytes()) {
Ok(v) => v,
Err(e) => {
let err = Box::new(error::BuildError::with_pos(
format!(
"{} include failed for {}",
&def.typ.fragment, &def.path.fragment
),
error::ErrorType::IncludeError,
def.pos.clone(),
));
return Err(err.wrap_cause(e).to_boxed());
}
}
};
Ok(val)
}

View File

@ -30,6 +30,7 @@ pub enum ErrorType {
NoSuchSymbol,
BadArgLen,
FormatError,
IncludeError,
ReservedWordError,
// Parsing Errors
ParseError,
@ -47,6 +48,7 @@ impl fmt::Display for ErrorType {
&ErrorType::NoSuchSymbol => "NoSuchSymbol",
&ErrorType::BadArgLen => "BadArgLen",
&ErrorType::FormatError => "FormatError",
&ErrorType::IncludeError => "IncludeError",
&ErrorType::ReservedWordError => "ReservedWordError",
&ErrorType::ParseError => "ParseError",
&ErrorType::AssertError => "AssertError",
@ -93,6 +95,10 @@ impl BuildError {
self
}
pub fn to_boxed(self) -> Box<Self> {
Box::new(self)
}
fn render(&self, w: &mut fmt::Formatter) -> fmt::Result {
if let Some(ref pos) = self.pos {
let file = match pos.file {

View File

@ -271,7 +271,7 @@ fn inspect_command(
match builder.eval_string(&normalized) {
Ok(v) => Some(v.clone()),
Err(e) => {
eprintln!("Err: {}", e);
eprintln!("{}", e);
process::exit(1);
}
}