From 45e8be4eab0fb91a532d59cb017a039a74ab6262 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sat, 6 Jul 2024 20:57:03 +0500 Subject: [PATCH] Use `.error_position()` instead of `.buffer_position()` in examples where error position is reported `.error_position()` is intended to report position where error start occurring, `.buffer_position()` is intended to show to what position reader read data tests/issues.rs leave untouched because this is the code from real problems in GH issues, it should remain as close to issue as possible --- README.md | 4 ++-- examples/custom_entities.rs | 2 +- examples/read_buffered.rs | 2 +- examples/read_texts.rs | 2 +- src/reader/async_tokio.rs | 2 +- src/reader/buffered_reader.rs | 2 +- src/reader/mod.rs | 2 +- src/writer.rs | 2 +- tests/reader.rs | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 058ab8cc..92804a06 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ loop { // when the input is a &str or a &[u8], we don't actually need to use another // buffer, we could directly call `reader.read_event()` match reader.read_event_into(&mut buf) { - Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), + Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), // exits the loop when reaching end of file Ok(Event::Eof) => break, @@ -98,7 +98,7 @@ loop { Ok(Event::Eof) => break, // we can either move or borrow the event to write, depending on your use-case Ok(e) => assert!(writer.write_event(e).is_ok()), - Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), + Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), } } diff --git a/examples/custom_entities.rs b/examples/custom_entities.rs index e68a6824..37d172ac 100644 --- a/examples/custom_entities.rs +++ b/examples/custom_entities.rs @@ -68,7 +68,7 @@ fn main() -> Result<(), Box> { ); } Ok(Event::Eof) => break, - Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), + Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), _ => (), } } diff --git a/examples/read_buffered.rs b/examples/read_buffered.rs index 4f0a20ec..d5e4cb4a 100644 --- a/examples/read_buffered.rs +++ b/examples/read_buffered.rs @@ -23,7 +23,7 @@ fn main() -> Result<(), quick_xml::Error> { count += 1; } Ok(Event::Eof) => break, // exits the loop when reaching end of file - Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), + Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), _ => (), // There are several other `Event`s we do not consider here } } diff --git a/examples/read_texts.rs b/examples/read_texts.rs index 666d1bdb..95ef0978 100644 --- a/examples/read_texts.rs +++ b/examples/read_texts.rs @@ -18,7 +18,7 @@ fn main() { println!("{:?}", txt); } Ok(Event::Eof) => break, // exits the loop when reaching end of file - Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), + Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), _ => (), // There are several other `Event`s we do not consider here } } diff --git a/src/reader/async_tokio.rs b/src/reader/async_tokio.rs index 7b8fa688..2e75b43f 100644 --- a/src/reader/async_tokio.rs +++ b/src/reader/async_tokio.rs @@ -58,7 +58,7 @@ impl Reader { /// match reader.read_event_into_async(&mut buf).await { /// Ok(Event::Start(_)) => count += 1, /// Ok(Event::Text(e)) => txt.push(e.unescape().unwrap().into_owned()), - /// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), + /// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), /// Ok(Event::Eof) => break, /// _ => (), /// } diff --git a/src/reader/buffered_reader.rs b/src/reader/buffered_reader.rs index 548eca92..c8af425e 100644 --- a/src/reader/buffered_reader.rs +++ b/src/reader/buffered_reader.rs @@ -328,7 +328,7 @@ impl Reader { /// match reader.read_event_into(&mut buf) { /// Ok(Event::Start(_)) => count += 1, /// Ok(Event::Text(e)) => txt.push(e.unescape().unwrap().into_owned()), - /// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), + /// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), /// Ok(Event::Eof) => break, /// _ => (), /// } diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 1cdf9030..46a30e86 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -589,7 +589,7 @@ impl EncodingRef { /// // when the input is a &str or a &[u8], we don't actually need to use another /// // buffer, we could directly call `reader.read_event()` /// match reader.read_event_into(&mut buf) { -/// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), +/// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), /// // exits the loop when reaching end of file /// Ok(Event::Eof) => break, /// diff --git a/src/writer.rs b/src/writer.rs index 81b7df34..5e16590f 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -52,7 +52,7 @@ use {crate::de::DeError, serde::Serialize}; /// Ok(Event::Eof) => break, /// // we can either move or borrow the event to write, depending on your use-case /// Ok(e) => assert!(writer.write_event(e.borrow()).is_ok()), -/// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e), +/// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e), /// } /// } /// diff --git a/tests/reader.rs b/tests/reader.rs index 4921cd87..2bc27e57 100644 --- a/tests/reader.rs +++ b/tests/reader.rs @@ -175,7 +175,7 @@ fn test_escaped_content() { Ok(c) => assert_eq!(c, ""), Err(e) => panic!( "cannot escape content at position {}: {:?}", - r.buffer_position(), + r.error_position(), e ), } @@ -183,7 +183,7 @@ fn test_escaped_content() { Ok(e) => panic!("Expecting text event, got {:?}", e), Err(e) => panic!( "Cannot get next event at position {}: {:?}", - r.buffer_position(), + r.error_position(), e ), }