Skip to content

Commit 45e8be4

Browse files
committed
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
1 parent df65be0 commit 45e8be4

File tree

9 files changed

+11
-11
lines changed

9 files changed

+11
-11
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ loop {
4040
// when the input is a &str or a &[u8], we don't actually need to use another
4141
// buffer, we could directly call `reader.read_event()`
4242
match reader.read_event_into(&mut buf) {
43-
Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
43+
Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
4444
// exits the loop when reaching end of file
4545
Ok(Event::Eof) => break,
4646

@@ -98,7 +98,7 @@ loop {
9898
Ok(Event::Eof) => break,
9999
// we can either move or borrow the event to write, depending on your use-case
100100
Ok(e) => assert!(writer.write_event(e).is_ok()),
101-
Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
101+
Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
102102
}
103103
}
104104

examples/custom_entities.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6868
);
6969
}
7070
Ok(Event::Eof) => break,
71-
Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
71+
Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
7272
_ => (),
7373
}
7474
}

examples/read_buffered.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> Result<(), quick_xml::Error> {
2323
count += 1;
2424
}
2525
Ok(Event::Eof) => break, // exits the loop when reaching end of file
26-
Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
26+
Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
2727
_ => (), // There are several other `Event`s we do not consider here
2828
}
2929
}

examples/read_texts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
println!("{:?}", txt);
1919
}
2020
Ok(Event::Eof) => break, // exits the loop when reaching end of file
21-
Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
21+
Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
2222
_ => (), // There are several other `Event`s we do not consider here
2323
}
2424
}

src/reader/async_tokio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<R: AsyncBufRead + Unpin> Reader<R> {
5858
/// match reader.read_event_into_async(&mut buf).await {
5959
/// Ok(Event::Start(_)) => count += 1,
6060
/// Ok(Event::Text(e)) => txt.push(e.unescape().unwrap().into_owned()),
61-
/// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
61+
/// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
6262
/// Ok(Event::Eof) => break,
6363
/// _ => (),
6464
/// }

src/reader/buffered_reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<R: BufRead> Reader<R> {
328328
/// match reader.read_event_into(&mut buf) {
329329
/// Ok(Event::Start(_)) => count += 1,
330330
/// Ok(Event::Text(e)) => txt.push(e.unescape().unwrap().into_owned()),
331-
/// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
331+
/// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
332332
/// Ok(Event::Eof) => break,
333333
/// _ => (),
334334
/// }

src/reader/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl EncodingRef {
589589
/// // when the input is a &str or a &[u8], we don't actually need to use another
590590
/// // buffer, we could directly call `reader.read_event()`
591591
/// match reader.read_event_into(&mut buf) {
592-
/// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
592+
/// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
593593
/// // exits the loop when reaching end of file
594594
/// Ok(Event::Eof) => break,
595595
///

src/writer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use {crate::de::DeError, serde::Serialize};
5252
/// Ok(Event::Eof) => break,
5353
/// // we can either move or borrow the event to write, depending on your use-case
5454
/// Ok(e) => assert!(writer.write_event(e.borrow()).is_ok()),
55-
/// Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
55+
/// Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
5656
/// }
5757
/// }
5858
///

tests/reader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ fn test_escaped_content() {
175175
Ok(c) => assert_eq!(c, "<test>"),
176176
Err(e) => panic!(
177177
"cannot escape content at position {}: {:?}",
178-
r.buffer_position(),
178+
r.error_position(),
179179
e
180180
),
181181
}
182182
}
183183
Ok(e) => panic!("Expecting text event, got {:?}", e),
184184
Err(e) => panic!(
185185
"Cannot get next event at position {}: {:?}",
186-
r.buffer_position(),
186+
r.error_position(),
187187
e
188188
),
189189
}

0 commit comments

Comments
 (0)