From 4e06e5d2baf99de503decfb3cc92240baf455ee4 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 5 Sep 2022 01:35:43 +0300 Subject: fix(tvix/eval): reintroduce 'InvalidAttribuetName' error variant As pointed out by sterni in cl/6205, this is actually possible in syntactically valid expressions like { ${12 + 13} = 12; } Change-Id: Id8a1e3aceb551f288f9050c4eea563eb6572f1a7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6461 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/errors.rs | 6 ++++++ tvix/eval/src/value/attrs.rs | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 2b8ba8f9631f..ad4acd479e05 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -6,6 +6,12 @@ pub enum ErrorKind { key: String, }, + /// Attempted to specify an invalid key type (e.g. integer) in a + /// dynamic attribute name. + InvalidAttributeName { + given: &'static str, + }, + AttributeNotFound { name: String, }, diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index fddf0b582ccb..b8ae51bf48fc 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -286,7 +286,11 @@ impl NixAttrs { continue; } - other => panic!("unexpected attribute key: {} :: {}", other, other.type_of()), + other => { + return Err(ErrorKind::InvalidAttributeName { + given: other.type_of(), + }) + } } } -- cgit 1.4.1