Skip to content

Commit 44e1517

Browse files
authored
chore: clarify error message for problem of field conflict (#734)
1 parent e7f3c54 commit 44e1517

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/execution/evaluator.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ impl<'a> ScopeKey<'a> {
143143
}
144144
}
145145

146+
impl std::fmt::Display for ScopeKey<'_> {
147+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
148+
match self {
149+
ScopeKey::None => write!(f, "()"),
150+
ScopeKey::MapKey(k) => write!(f, "{{{k}}}"),
151+
ScopeKey::ListIndex(i) => write!(f, "[{i}]"),
152+
}
153+
}
154+
}
155+
146156
struct ScopeEntry<'a> {
147157
key: ScopeKey<'a>,
148158
value: &'a ScopeValueBuilder,
@@ -254,19 +264,20 @@ impl<'a> ScopeEntry<'a> {
254264
&self,
255265
output_field: &AnalyzedOpOutput,
256266
val: value::Value<ScopeValueBuilder>,
257-
) {
267+
) -> Result<()> {
258268
let field_index = output_field.field_idx as usize;
259269
let index_base = self.key.value_field_index_base() as usize;
260-
self.value.fields[field_index - index_base]
261-
.set(val)
262-
.expect("Field is already set, violating single-definition rule");
270+
self.value.fields[field_index - index_base].set(val).map_err(|_| {
271+
anyhow!("Field {field_index} for scope is already set, violating single-definition rule.")
272+
})?;
273+
Ok(())
263274
}
264275

265276
fn define_field(&self, output_field: &AnalyzedOpOutput, val: &value::Value) -> Result<()> {
266277
let field_index = output_field.field_idx as usize;
267278
let field_schema = &self.schema.fields[field_index];
268279
let val = augmented_value(val, &field_schema.value_type.typ)?;
269-
self.define_field_w_builder(output_field, val);
280+
self.define_field_w_builder(output_field, val)?;
270281
Ok(())
271282
}
272283
}

0 commit comments

Comments
 (0)