feat(tvix/eval): ensure all errors always carry a span
Previously error spans were optional because the information about code spans was not available at runtime. Now that this information has been added, the error type will always carry a span. This change is very invasive all throughout the codebase. This is due to the fact that many functions that are called *by* the VM expected to return `EvalResult`, but this no longer works as the span information is not available to those functions - only to the VM itself. To work around this the majority of these functions have been changed to return `Result<T, ErrorKind>` instead and an accompanying macro in the VM constructs the "real" error. Note that this implementatino currently has a bug where errors occuring within thunks will yield the location at which the thunk was forced, not the location at which the error occured within the code. This will be fixed soon, but the commit is large enough as is. Change-Id: Ib1ecb81a4d09d464a95ea7ea9e589f3bd08d5202 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6408 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
197fe37dae
commit
377ba19d75
9 changed files with 149 additions and 141 deletions
|
|
@ -1217,10 +1217,7 @@ impl Compiler<'_> {
|
|||
}
|
||||
|
||||
fn emit_error(&mut self, span: codemap::Span, kind: ErrorKind) {
|
||||
self.errors.push(Error {
|
||||
kind,
|
||||
span: Some(span),
|
||||
})
|
||||
self.errors.push(Error { kind, span })
|
||||
}
|
||||
|
||||
/// Convert a non-dynamic string expression to a string if possible,
|
||||
|
|
@ -1234,7 +1231,7 @@ impl Compiler<'_> {
|
|||
|
||||
return Err(Error {
|
||||
kind: ErrorKind::DynamicKeyInLet(expr.syntax().clone()),
|
||||
span: Some(self.span_for(&expr)),
|
||||
span: self.span_for(&expr),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1253,7 +1250,7 @@ impl Compiler<'_> {
|
|||
ast::Expr::Str(s) => self.expr_str_to_string(s),
|
||||
_ => Err(Error {
|
||||
kind: ErrorKind::DynamicKeyInLet(node.syntax().clone()),
|
||||
span: Some(self.span_for(&node)),
|
||||
span: self.span_for(&node),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
|
@ -1319,8 +1316,12 @@ pub fn compile<'code>(
|
|||
) -> EvalResult<CompilationOutput> {
|
||||
let mut root_dir = match location {
|
||||
Some(dir) => Ok(dir),
|
||||
None => std::env::current_dir().map_err(|e| {
|
||||
ErrorKind::PathResolution(format!("could not determine current directory: {}", e))
|
||||
None => std::env::current_dir().map_err(|e| Error {
|
||||
kind: ErrorKind::PathResolution(format!(
|
||||
"could not determine current directory: {}",
|
||||
e
|
||||
)),
|
||||
span: file.span,
|
||||
}),
|
||||
}?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue