Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit 9c1f20b

Browse files
feat!: add pretty-print for repl output + small error messaging improvement (#274)
1 parent 1c150cd commit 9c1f20b

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tools/repl/src/repl.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use fluence_app_service::{AppService, CallParameters, SecurityTetraplet};
2424
use fluence_app_service::MarineModuleConfig;
2525
use fluence_app_service::TomlAppServiceConfig;
2626

27+
use anyhow::anyhow;
2728
use serde::Deserialize;
2829
use serde_json::Value as JValue;
2930

@@ -176,7 +177,16 @@ impl REPL {
176177
{
177178
Ok(result) if show_result_arg => {
178179
let elapsed_time = start.elapsed();
179-
format!("result: {:?}\n elapsed time: {:?}", result, elapsed_time)
180+
181+
let result_string = match serde_json::to_string_pretty(&result) {
182+
Ok(pretty_printed) => pretty_printed,
183+
Err(_) => format!("{:?}", result),
184+
};
185+
186+
format!(
187+
"result: {}\n elapsed time: {:?}",
188+
result_string, elapsed_time
189+
)
180190
}
181191
Ok(_) => {
182192
let elapsed_time = start.elapsed();
@@ -229,7 +239,19 @@ impl REPL {
229239
let mut config = config_file_path
230240
.as_ref()
231241
.map(TomlAppServiceConfig::load)
232-
.transpose()?
242+
.transpose()
243+
.map_err(|e| {
244+
anyhow!(
245+
"failed to load \"{}\": {}",
246+
config_file_path
247+
.as_ref()
248+
.unwrap_or_else(|| panic!(
249+
"config_file_path is Some because it is used to load file"
250+
))
251+
.display(),
252+
e
253+
)
254+
})?
233255
.unwrap_or_default();
234256
config.service_base_dir = Some(tmp_path);
235257

0 commit comments

Comments
 (0)