diff options
author | Griffin Smith <root@gws.fyi> | 2022-09-18T16·06-0400 |
---|---|---|
committer | grfn <grfn@gws.fyi> | 2022-09-18T16·40+0000 |
commit | d431aa7743f0956cd31ab64b73bbee469783ba51 (patch) | |
tree | 133cd7ecc6a6277437c2c939b8d10e8ce62b03d4 /tvix/eval/src/errors.rs | |
parent | b3cc4c8c2c25008699323491ee2456bd317efeac (diff) |
fix(tvix/eval): Emit errors for invalid integers r/4898
Invalid integers (eg integers that're too long) end up as error returns on the `.value()` returned from the literal in the AST - previously we'd unwrap this error, causing it to panic the compiler, but now we've got a nice error variant for it (which just unwraps the underlying std::num::ParseIntError). Change-Id: I50c3c5ba89407d86659e20d8991b9658415f39a0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6635 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/errors.rs')
-rw-r--r-- | tvix/eval/src/errors.rs | 16 |
1 files changed, 15 insertions, 1 deletions
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", } } |