evmbin: escape newlines in json errors (#9458)
This commit is contained in:
parent
c0eb30b604
commit
1f2426226b
@ -95,7 +95,7 @@ impl vm::Informant for Informant {
|
|||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{{\"error\":\"{error}\",\"gasUsed\":\"{gas:x}\",\"time\":{time}}}",
|
"{{\"error\":\"{error}\",\"gasUsed\":\"{gas:x}\",\"time\":{time}}}",
|
||||||
error = failure.error,
|
error = display::escape_newlines(&failure.error),
|
||||||
gas = failure.gas_used,
|
gas = failure.gas_used,
|
||||||
time = display::as_micros(&failure.time),
|
time = display::as_micros(&failure.time),
|
||||||
)
|
)
|
||||||
|
@ -31,3 +31,7 @@ pub fn format_time(time: &Duration) -> String {
|
|||||||
pub fn as_micros(time: &Duration) -> u64 {
|
pub fn as_micros(time: &Duration) -> u64 {
|
||||||
time.as_secs() * 1_000_000 + time.subsec_nanos() as u64 / 1_000
|
time.as_secs() * 1_000_000 + time.subsec_nanos() as u64 / 1_000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn escape_newlines<D: ::std::fmt::Display>(s: D) -> String {
|
||||||
|
format!("{}", s).replace("\r\n", "\n").replace('\n', "\\n")
|
||||||
|
}
|
||||||
|
@ -129,7 +129,7 @@ impl<Trace: Writer, Out: Writer> vm::Informant for Informant<Trace, Out> {
|
|||||||
writeln!(
|
writeln!(
|
||||||
&mut out_sink,
|
&mut out_sink,
|
||||||
"{{\"error\":\"{error}\",\"gasUsed\":\"0x{gas:x}\",\"time\":{time}}}",
|
"{{\"error\":\"{error}\",\"gasUsed\":\"0x{gas:x}\",\"time\":{time}}}",
|
||||||
error = failure.error,
|
error = display::escape_newlines(&failure.error),
|
||||||
gas = failure.gas_used,
|
gas = failure.gas_used,
|
||||||
time = display::as_micros(&failure.time),
|
time = display::as_micros(&failure.time),
|
||||||
).expect("The sink must be writeable.");
|
).expect("The sink must be writeable.");
|
||||||
|
Loading…
Reference in New Issue
Block a user