about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-10-22T14·20+0300
committertazjin <tazjin@tvl.su>2022-10-22T18·30+0000
commit4ff06ba67dbe5397a97c2bae78e25d0ab8c026a3 (patch)
treee701de2236ab2ccc4aab741688c0a3efc802b880
parent359444360b42c428ae10e1ad612a6f4966f11652 (diff)
feat(tvix/eval): add `TvixBug` error kind r/5177
This can be raised in cases where some panics lurk (e.g. indexed
accesses).

Change-Id: I93f4d60568277e9c5635aa52f378645626d68c5e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7057
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
-rw-r--r--tvix/eval/src/errors.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index 5437db7bcb..8f782cb861 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -5,7 +5,7 @@ use std::path::PathBuf;
 use std::rc::Rc;
 use std::str::Utf8Error;
 use std::sync::Arc;
-use std::{fmt::Display, num::ParseIntError};
+use std::{fmt::Debug, fmt::Display, num::ParseIntError};
 
 use codemap::{File, Span};
 use codemap_diagnostic::{ColorConfig, Diagnostic, Emitter, Level, SpanLabel, SpanStyle};
@@ -141,6 +141,13 @@ pub enum ErrorKind {
         formals_span: Span,
     },
 
+    /// Variant for code paths that are known bugs in Tvix (usually
+    /// issues with the compiler/VM interaction).
+    TvixBug {
+        msg: &'static str,
+        metadata: Option<Rc<dyn Debug>>,
+    },
+
     /// Tvix internal warning for features triggered by users that are
     /// not actually implemented yet, and without which eval can not
     /// proceed.
@@ -376,6 +383,16 @@ to a missing value in the attribute set(s) included via `with`."#,
                 )
             }
 
+            ErrorKind::TvixBug { msg, metadata } => {
+                write!(f, "Tvix bug: {}", msg)?;
+
+                if let Some(metadata) = metadata {
+                    write!(f, "; metadata: {:?}", metadata)?;
+                }
+
+                Ok(())
+            }
+
             ErrorKind::NotImplemented(feature) => {
                 write!(f, "feature not yet implemented in Tvix: {}", feature)
             }
@@ -658,6 +675,7 @@ impl Error {
             | ErrorKind::ImportCompilerError { .. }
             | ErrorKind::IO { .. }
             | ErrorKind::FromJsonError(_)
+            | ErrorKind::TvixBug { .. }
             | ErrorKind::NotImplemented(_) => return None,
         };
 
@@ -700,6 +718,10 @@ impl Error {
             ErrorKind::UnexpectedArgument { .. } => "E031",
             ErrorKind::RelativePathResolution(_) => "E032",
 
+            // Special error code that is not part of the normal
+            // ordering.
+            ErrorKind::TvixBug { .. } => "E998",
+
             // Placeholder error while Tvix is under construction.
             ErrorKind::NotImplemented(_) => "E999",