From 68536ac81fc2555a85a811437a4eaa4e5103b1af Mon Sep 17 00:00:00 2001 From: Greg Brandt Date: Sun, 15 Feb 2026 22:00:11 -0800 Subject: [PATCH] Handle incorrect sync markers in count tool gracefully - Include total count in Sync marker exception - Just log a warning in count tool when sync doesn't match --- avrokit/tools/count.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/avrokit/tools/count.py b/avrokit/tools/count.py index a471de0..06f6144 100644 --- a/avrokit/tools/count.py +++ b/avrokit/tools/count.py @@ -47,10 +47,19 @@ def fast_count_records(self, reader: avro.datafile.DataFileReader) -> int: # Check sync marker marker = reader.reader.read(16) if marker != sync_marker: - raise avro.errors.AvroException("Sync marker does not match") + raise avro.errors.AvroException( + f"Sync marker does not match (after {total} records)" + ) except EOFError: break # End of file reached except avro.errors.AvroException as e: + if "Sync marker does not match" in str(e): + self.logger.warning( + "File may still be open for writing (sync mismatch after %d records). " + "Counting records up to last valid sync marker.", + total, + ) + break if "Read 0 bytes, expected 1 bytes" in str(e): break # Normal end of file for Avro self.logger.error(f"Avro error while reading block: {e}")