Skip to content

Commit 9fa9b8e

Browse files
author
default
committed
fix: Downgrade assert to debug_assert
I've also added a check that should prevent the debug_assert from ever happening.
1 parent 02ff0c9 commit 9fa9b8e

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

avro/src/ser_schema.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ impl<'a, 's, W: Write> SchemaAwareWriteSerializeStruct<'a, 's, W> {
292292
self.bytes_written += bytes.len();
293293
self.field_position += 1;
294294
}
295-
} else {
296-
// This field is in the wrong order, write it to a temporary buffer so we can add it at the right time
295+
} else if field.position > self.field_position {
296+
// We're still missing at least one field, save this field temporarily
297297
let mut bytes = Vec::new();
298298
let mut value_ser = SchemaAwareWriteSerializer::new(
299299
&mut bytes,
@@ -305,6 +305,9 @@ impl<'a, 's, W: Write> SchemaAwareWriteSerializeStruct<'a, 's, W> {
305305
if self.field_cache.insert(field.position, bytes).is_some() {
306306
return Err(Details::FieldNameDuplicate(field.name.clone()).into());
307307
}
308+
} else {
309+
// We've already had this field
310+
return Err(Details::FieldNameDuplicate(field.name.clone()).into());
308311
}
309312
Ok(())
310313
}
@@ -336,12 +339,7 @@ impl<'a, 's, W: Write> SchemaAwareWriteSerializeStruct<'a, 's, W> {
336339
}
337340
}
338341

339-
// Check if all fields were written
340-
if self.field_position != self.record_schema.fields.len() {
341-
let name = self.record_schema.fields[self.field_position].name.clone();
342-
return Err(Details::GetField(name).into());
343-
}
344-
assert!(
342+
debug_assert!(
345343
self.field_cache.is_empty(),
346344
"There should be no more unwritten fields at this point: {:?}",
347345
self.field_cache

0 commit comments

Comments
 (0)