slightly nicer JSON write_all
This commit is contained in:
parent
a2ce336fe7
commit
1f46bef10b
1 changed files with 7 additions and 16 deletions
|
@ -12,7 +12,7 @@ use snailquote::escape;
|
||||||
use crate::findings::ScanError;
|
use crate::findings::ScanError;
|
||||||
use crate::utils::clap_long_version;
|
use crate::utils::clap_long_version;
|
||||||
use crate::Findings;
|
use crate::Findings;
|
||||||
use itertools::Itertools;
|
use itertools::{Either, Itertools};
|
||||||
|
|
||||||
/// A macro for creating an array of `Writable`s without needing to pepper your code with `into()`s.
|
/// A macro for creating an array of `Writable`s without needing to pepper your code with `into()`s.
|
||||||
/// # Usage
|
/// # Usage
|
||||||
|
@ -340,21 +340,12 @@ impl Format for Json {
|
||||||
findings: &'a Vec<&'a Findings>,
|
findings: &'a Vec<&'a Findings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = serde_json::to_writer_pretty(
|
let (errors, findings) = &entries.iter().partition_map(|entry| match entry {
|
||||||
f,
|
Err(e) => Either::Left(e),
|
||||||
&SerdeEntries {
|
Ok(f) => Either::Right(f),
|
||||||
errors: &entries
|
});
|
||||||
.iter()
|
|
||||||
.filter_map(|e| e.as_ref().err())
|
let result = serde_json::to_writer_pretty(f, &SerdeEntries { errors, findings });
|
||||||
.sorted_unstable()
|
|
||||||
.collect(),
|
|
||||||
findings: &entries
|
|
||||||
.iter()
|
|
||||||
.filter_map(|f| f.as_ref().ok())
|
|
||||||
.sorted_unstable()
|
|
||||||
.collect(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
log::error!("Error while serialising: {}", err);
|
log::error!("Error while serialising: {}", err);
|
||||||
|
|
Loading…
Reference in a new issue