Skip to content

Conversation

@digizeph
Copy link
Member

@digizeph digizeph commented Aug 4, 2025

Summary

This PR implements fallible iterators that expose parsing errors to users, addressing the current limitation where errors are silently skipped and only logged as warnings.

New Features:

  • FallibleRecordIterator - Returns Result<MrtRecord, ParserErrorWithBytes> instead of skipping errors
  • FallibleElemIterator - Returns Result<BgpElem, ParserErrorWithBytes> instead of skipping errors
  • into_fallible_record_iter() and into_fallible_elem_iter() methods on BgpkitParser

Key Benefits:

  • Users can now handle parsing errors explicitly instead of having them silently skipped
  • Full backward compatibility maintained - existing iterators unchanged
  • Better error visibility for debugging and data quality monitoring
  • Follows Rust error handling best practices

Module Reorganization:

  • Restructured iterator implementations into iters module with default and fallible submodules
  • Cleaner separation of concerns between error-skipping and error-exposing iterators
  • All trait implementations consolidated in iters/mod.rs

Test Plan

  • All existing tests pass (246 tests)
  • Added comprehensive test coverage for fallible iterators (4 new tests)
  • Example code demonstrating usage patterns (examples/fallible_parsing.rs)
  • Verified backward compatibility - no breaking changes
  • Code formatting and clippy checks pass
  • Build verification with and without default features

Usage Example

use bgpkit_parser::BgpkitParser;

let parser = BgpkitParser::new("updates.mrt").unwrap();
for result in parser.into_fallible_record_iter() {
    match result {
        Ok(record) => {
            // Process the record normally
        }
        Err(e) => {
            // Handle the parsing error explicitly
            eprintln\!("Error parsing record: {}", e);
        }
    }
}

Backward Compatibility

No breaking changes - all existing APIs remain unchanged
Default behavior preserved - standard iterators continue to skip errors
Additive only - new functionality is opt-in via new methods

* implement FallibleRecordIterator that returns Result<MrtRecord, ParserErrorWithBytes>
* implement FallibleElemIterator that returns Result<BgpElem, ParserErrorWithBytes>
* add into_fallible_record_iter() and into_fallible_elem_iter() methods on BgpkitParser
* allow users to handle parsing errors explicitly instead of having them silently skipped
* maintain full backward compatibility with existing error-skipping iterators
* reorganize iterator implementations into structured iters module with default and fallible submodules
* add comprehensive test coverage for fallible iterator behavior
* include example demonstrating fallible iterator usage patterns
@digizeph digizeph merged commit 6e728be into main Aug 4, 2025
2 of 3 checks passed
@digizeph digizeph deleted the fallable-iterator branch August 4, 2025 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants