Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit 1c031a6

Browse files
committed
Omit position 0 from error messages
1 parent 3562a13 commit 1c031a6

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎src/error.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ impl ErrorImpl {
252252
_ => {
253253
self.message_no_mark(f)?;
254254
if let Some(mark) = self.mark() {
255-
write!(f, " at {}", mark)?;
255+
if mark.line() != 0 || mark.column() != 0 {
256+
write!(f, " at {}", mark)?;
257+
}
256258
}
257259
Ok(())
258260
}

‎tests/test_error.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn test_missing_enum_tag() {
154154
"V": 16
155155
"other": 32
156156
"#};
157-
let expected = "invalid type: map, expected a YAML tag starting with '!' at position 0";
157+
let expected = "invalid type: map, expected a YAML tag starting with '!'";
158158
test_error::<E>(yaml, expected);
159159
}
160160

@@ -245,7 +245,7 @@ fn test_struct_from_sequence() {
245245
let yaml = indoc! {"
246246
[0, 0]
247247
"};
248-
let expected = "invalid type: sequence, expected struct Struct at position 0";
248+
let expected = "invalid type: sequence, expected struct Struct";
249249
test_error::<Struct>(yaml, expected);
250250
}
251251

@@ -332,7 +332,7 @@ fn test_infinite_recursion_objects() {
332332
}
333333

334334
let yaml = "&a {'x': *a}";
335-
let expected = "recursion limit exceeded at position 0";
335+
let expected = "recursion limit exceeded";
336336
test_error::<S>(yaml, expected);
337337
}
338338

@@ -343,7 +343,7 @@ fn test_infinite_recursion_arrays() {
343343
struct S(usize, Option<Box<S>>);
344344

345345
let yaml = "&a [0, *a]";
346-
let expected = "recursion limit exceeded at position 0";
346+
let expected = "recursion limit exceeded";
347347
test_error::<S>(yaml, expected);
348348
}
349349

@@ -354,7 +354,7 @@ fn test_infinite_recursion_newtype() {
354354
struct S(Option<Box<S>>);
355355

356356
let yaml = "&a [*a]";
357-
let expected = "recursion limit exceeded at position 0";
357+
let expected = "recursion limit exceeded";
358358
test_error::<S>(yaml, expected);
359359
}
360360

0 commit comments

Comments
 (0)