From 4ff06ba67dbe5397a97c2bae78e25d0ab8c026a3 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 22 Oct 2022 17:20:11 +0300 Subject: feat(tvix/eval): add `TvixBug` error kind 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 Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tvix/eval') 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>, + }, + /// 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", -- cgit 1.4.1