mirror of
https://github.com/serde-rs/json.git
synced 2025-09-30 14:32: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 {
|
||||
code: ErrorCode,
|
||||
line: usize,
|
||||
@ -188,7 +187,6 @@ struct ErrorImpl {
|
||||
|
||||
// Not public API. Should be pub(crate).
|
||||
#[doc(hidden)]
|
||||
#[derive(Debug)]
|
||||
pub enum ErrorCode {
|
||||
/// Catchall for syntax error messages
|
||||
Message(Box<str>),
|
||||
@ -382,7 +380,13 @@ impl Display for ErrorImpl {
|
||||
// end up seeing this representation because it is what unwrap() shows.
|
||||
impl Debug for Error {
|
||||
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]
|
||||
extern crate serde_json;
|
||||
|
||||
use serde_json::Number;
|
||||
use serde_json::{Number, Value};
|
||||
|
||||
#[test]
|
||||
fn number() {
|
||||
@ -45,3 +45,10 @@ fn value_array() {
|
||||
fn value_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