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!(
|
||||
"{{\"error\":\"{error}\",\"gasUsed\":\"{gas:x}\",\"time\":{time}}}",
|
||||
error = failure.error,
|
||||
error = display::escape_newlines(&failure.error),
|
||||
gas = failure.gas_used,
|
||||
time = display::as_micros(&failure.time),
|
||||
)
|
||||
|
@ -31,3 +31,7 @@ pub fn format_time(time: &Duration) -> String {
|
||||
pub fn as_micros(time: &Duration) -> u64 {
|
||||
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!(
|
||||
&mut out_sink,
|
||||
"{{\"error\":\"{error}\",\"gasUsed\":\"0x{gas:x}\",\"time\":{time}}}",
|
||||
error = failure.error,
|
||||
error = display::escape_newlines(&failure.error),
|
||||
gas = failure.gas_used,
|
||||
time = display::as_micros(&failure.time),
|
||||
).expect("The sink must be writeable.");
|
||||
|
Loading…
Reference in New Issue
Block a user