diff options
-rw-r--r-- | tvix/eval/src/compiler/mod.rs | 5 | ||||
-rw-r--r-- | tvix/eval/src/errors.rs | 16 |
2 files changed, 19 insertions, 2 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 52b6e8e542ee..4d6728b6d6c3 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -192,7 +192,10 @@ impl Compiler<'_, '_> { fn compile_literal(&mut self, node: ast::Literal) { let value = match node.kind() { ast::LiteralKind::Float(f) => Value::Float(f.value().unwrap()), - ast::LiteralKind::Integer(i) => Value::Integer(i.value().unwrap()), + ast::LiteralKind::Integer(i) => match i.value() { + Ok(v) => Value::Integer(v), + Err(err) => return self.emit_error(&node, err.into()), + }, ast::LiteralKind::Uri(u) => { self.emit_warning(&node, WarningKind::DeprecatedLiteralURL); diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index d3d41cbbcd48..1b8f58356cab 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -1,6 +1,6 @@ use crate::value::CoercionKind; -use std::fmt::Display; use std::path::PathBuf; +use std::{fmt::Display, num::ParseIntError}; use codemap::{CodeMap, Span}; use codemap_diagnostic::{Diagnostic, Emitter, Level, SpanLabel, SpanStyle}; @@ -77,12 +77,21 @@ pub enum ErrorKind { /// The given string doesn't represent an absolute path NotAnAbsolutePath(PathBuf), + /// An error occurred when parsing an integer + ParseIntError(ParseIntError), + /// Tvix internal warning for features triggered by users that are /// not actually implemented yet, and without which eval can not /// proceed. NotImplemented(&'static str), } +impl From<ParseIntError> for ErrorKind { + fn from(e: ParseIntError) -> Self { + Self::ParseIntError(e) + } +} + #[derive(Clone, Debug)] pub struct Error { pub kind: ErrorKind, @@ -200,6 +209,10 @@ to a missing value in the attribute set(s) included via `with`."#, ) } + ErrorKind::ParseIntError(err) => { + format!("invalid integer: {}", err) + } + ErrorKind::NotImplemented(feature) => { format!("feature not yet implemented in Tvix: {}", feature) } @@ -230,6 +243,7 @@ to a missing value in the attribute set(s) included via `with`."#, ErrorKind::NotCoercibleToString { .. } => "E018", ErrorKind::IndexOutOfBounds { .. } => "E019", ErrorKind::NotAnAbsolutePath(_) => "E020", + ErrorKind::ParseIntError(_) => "E021", ErrorKind::NotImplemented(_) => "E999", } } |