Skip to content

Commit

Permalink
Do not print json with new line characters
Browse files Browse the repository at this point in the history
  • Loading branch information
emostov committed Oct 9, 2023
1 parent a3c60d3 commit 44a07c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/enclave_proc_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ pub fn enclave_process_handle_all_replies<T>(
prev_failed_conns: usize,
print_as_vec: bool,
allowed_return_codes: Vec<i32>,
pretty_print: bool,
) -> NitroCliResult<Vec<T>>
where
T: Clone + DeserializeOwned + Serialize,
Expand All @@ -318,18 +319,28 @@ where
// Output the received objects either individually or as an array.
if print_as_vec {
let obj_vec: Vec<T> = objects.iter().map(|v| v.0.clone()).collect();
let json_result = if pretty_print {
serde_json::to_string_pretty(&obj_vec)
} else {
serde_json::to_string(&obj_vec)
};
println!(
"{}",
serde_json::to_string_pretty(&obj_vec).map_err(|e| new_nitro_cli_failure!(
json_result.map_err(|e| new_nitro_cli_failure!(
&format!("Failed to print JSON vector: {:?}", e),
NitroCliErrorEnum::SerdeError
))?
);
} else {
for object in objects.iter().map(|v| v.0.clone()) {
let json_result = if pretty_print {
serde_json::to_string_pretty(&object)
} else {
serde_json::to_string(&object)
};
println!(
"{}",
serde_json::to_string_pretty(&object).map_err(|e| new_nitro_cli_failure!(
json_result.map_err(|e| new_nitro_cli_failure!(
&format!("Failed to print JSON object: {:?}", e),
NitroCliErrorEnum::SerdeError
))?
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ pub fn terminate_all_enclaves() -> NitroCliResult<()> {
failed_connections.len() + err_socket_files,
false,
vec![0, libc::EACCES],
true,
)
.map_err(|e| e.add_subaction("Failed to handle all enclave processes replies".to_string()))
.map(|_| ())
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn main() {
0,
false,
vec![0],
true,
)
.map_err(|e| {
e.add_subaction("Failed to handle all enclave process replies".to_string())
Expand Down Expand Up @@ -177,6 +178,7 @@ fn main() {
0,
false,
vec![0],
true,
)
.map_err(|e| {
e.add_subaction("Failed to handle all enclave process replies".to_string())
Expand Down Expand Up @@ -206,6 +208,7 @@ fn main() {
comm_errors,
true,
vec![0],
true,
)
.map_err(|e| {
e.add_subaction("Failed to handle all enclave process replies".to_string())
Expand Down

0 comments on commit 44a07c0

Please sign in to comment.