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");
|
eprintln!("including an empty file. Use NULL as the result");
|
||||||
Rc::new(Val::Empty)
|
Rc::new(Val::Empty)
|
||||||
} else {
|
} else {
|
||||||
// FIXME(jwall): This should be wrapped in a BuildError
|
match importer.import(file_contents.as_bytes()) {
|
||||||
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)
|
Ok(val)
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ pub enum ErrorType {
|
|||||||
NoSuchSymbol,
|
NoSuchSymbol,
|
||||||
BadArgLen,
|
BadArgLen,
|
||||||
FormatError,
|
FormatError,
|
||||||
|
IncludeError,
|
||||||
ReservedWordError,
|
ReservedWordError,
|
||||||
// Parsing Errors
|
// Parsing Errors
|
||||||
ParseError,
|
ParseError,
|
||||||
@ -47,6 +48,7 @@ impl fmt::Display for ErrorType {
|
|||||||
&ErrorType::NoSuchSymbol => "NoSuchSymbol",
|
&ErrorType::NoSuchSymbol => "NoSuchSymbol",
|
||||||
&ErrorType::BadArgLen => "BadArgLen",
|
&ErrorType::BadArgLen => "BadArgLen",
|
||||||
&ErrorType::FormatError => "FormatError",
|
&ErrorType::FormatError => "FormatError",
|
||||||
|
&ErrorType::IncludeError => "IncludeError",
|
||||||
&ErrorType::ReservedWordError => "ReservedWordError",
|
&ErrorType::ReservedWordError => "ReservedWordError",
|
||||||
&ErrorType::ParseError => "ParseError",
|
&ErrorType::ParseError => "ParseError",
|
||||||
&ErrorType::AssertError => "AssertError",
|
&ErrorType::AssertError => "AssertError",
|
||||||
@ -93,6 +95,10 @@ impl BuildError {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_boxed(self) -> Box<Self> {
|
||||||
|
Box::new(self)
|
||||||
|
}
|
||||||
|
|
||||||
fn render(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
fn render(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
||||||
if let Some(ref pos) = self.pos {
|
if let Some(ref pos) = self.pos {
|
||||||
let file = match pos.file {
|
let file = match pos.file {
|
||||||
|
@ -271,7 +271,7 @@ fn inspect_command(
|
|||||||
match builder.eval_string(&normalized) {
|
match builder.eval_string(&normalized) {
|
||||||
Ok(v) => Some(v.clone()),
|
Ok(v) => Some(v.clone()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Err: {}", e);
|
eprintln!("{}", e);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user