mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
FEATURE: Wrap include failures in a Build Error.
This is way more ergonomic for the users.
This commit is contained in:
parent
014710a4ba
commit
1699801895
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user