Skip to content

Commit ba777f3

Browse files
committed
feat: panic on record() if field wasn't found.
Even though this is a breaking change, it happens at runtime and should be helpful.
1 parent 8341d08 commit ba777f3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

gix-trace/src/enabled.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ impl Span {
3232

3333
/// Record a single `field` to take `value`.
3434
///
35-
/// Note that this silently fails if the field name wasn't mentioned when the span was created.
35+
/// ### Panics
36+
///
37+
/// If the field name wasn't mentioned when the span was created.
3638
pub fn record<V>(&self, field: &str, value: V) -> &Self
3739
where
3840
V: field::Value,
3941
{
4042
if let Some((_, _, meta)) = &self.id {
4143
let fields = meta.fields();
42-
if let Some(field) = fields.field(field) {
43-
self.record_all(&fields.value_set(&[(&field, Some(&value as &dyn field::Value))]));
44-
}
44+
let field = fields
45+
.field(field)
46+
.unwrap_or_else(|| panic!("Field name '{field}' must be registered at creation time."));
47+
self.record_all(&fields.value_set(&[(&field, Some(&value as &dyn field::Value))]));
4548
}
4649
self
4750
}

0 commit comments

Comments
 (0)