about summary refs log tree commit diff
path: root/tvix/eval/src/errors.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-22T20·20+0300
committertazjin <tazjin@tvl.su>2022-09-01T21·40+0000
commit2662376941367d88687b3ebc4e4b941b266cee42 (patch)
tree9202de6ecebcb9d03e7940d0ddf8227f6a4ef1e1 /tvix/eval/src/errors.rs
parent51be6542c98158feb89e0e2d89f6b5165a070914 (diff)
feat(tvix/eval): carry optional SyntaxNode in error type r/4571
This starts paving the way for nicer, source-code based error
reporting.

Right now the code paths in the VM do not emit annotated errors, as we
do not yet preserve that structure from the compiler. However, error
emitting code paths in the compiler have been amended to include known
nodes.

Change-Id: I1b74410ffd891c40cd913361bd73c4336ec8aa5b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6235
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/errors.rs')
-rw-r--r--tvix/eval/src/errors.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index 4aba877f49..01a5e81449 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -1,7 +1,7 @@
 use std::fmt::Display;
 
 #[derive(Debug)]
-pub enum Error {
+pub enum ErrorKind {
     DuplicateAttrsKey {
         key: String,
     },
@@ -37,9 +37,21 @@ pub enum Error {
     AssertionFailed,
 }
 
+#[derive(Debug)]
+pub struct Error {
+    pub node: Option<rnix::SyntaxNode>,
+    pub kind: ErrorKind,
+}
+
+impl From<ErrorKind> for Error {
+    fn from(kind: ErrorKind) -> Self {
+        Error { node: None, kind }
+    }
+}
+
 impl Display for Error {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        writeln!(f, "{:?}", self)
+        writeln!(f, "{:?}", self.kind)
     }
 }