mirror of
https://github.com/serde-rs/json.git
synced 2025-10-03 07:46:05 +00:00
Cleaner Debug representation of Error
This commit is contained in:
parent
77a8c3af9c
commit
28ea01fbb9
10
src/error.rs
10
src/error.rs
@ -179,7 +179,6 @@ impl From<Error> for io::Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct ErrorImpl {
|
struct ErrorImpl {
|
||||||
code: ErrorCode,
|
code: ErrorCode,
|
||||||
line: usize,
|
line: usize,
|
||||||
@ -188,7 +187,6 @@ struct ErrorImpl {
|
|||||||
|
|
||||||
// Not public API. Should be pub(crate).
|
// Not public API. Should be pub(crate).
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum ErrorCode {
|
pub enum ErrorCode {
|
||||||
/// Catchall for syntax error messages
|
/// Catchall for syntax error messages
|
||||||
Message(Box<str>),
|
Message(Box<str>),
|
||||||
@ -382,7 +380,13 @@ impl Display for ErrorImpl {
|
|||||||
// end up seeing this representation because it is what unwrap() shows.
|
// end up seeing this representation because it is what unwrap() shows.
|
||||||
impl Debug for Error {
|
impl Debug for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
Debug::fmt(&*self.err, f)
|
write!(
|
||||||
|
f,
|
||||||
|
"Error({:?}, line: {}, column: {})",
|
||||||
|
self.err.code.to_string(),
|
||||||
|
self.err.line,
|
||||||
|
self.err.column
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use serde_json::Number;
|
use serde_json::{Number, Value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number() {
|
fn number() {
|
||||||
@ -45,3 +45,10 @@ fn value_array() {
|
|||||||
fn value_object() {
|
fn value_object() {
|
||||||
assert_eq!(format!("{:?}", json!({})), "Object({})");
|
assert_eq!(format!("{:?}", json!({})), "Object({})");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn error() {
|
||||||
|
let err = serde_json::from_str::<Value>("{0}").unwrap_err();
|
||||||
|
let expected = "Error(\"key must be a string\", line: 1, column: 2)";
|
||||||
|
assert_eq!(format!("{:?}", err), expected);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user