Skip to content

Commit a0c94cb

Browse files
committed
refactor(client-cli): rephrase error messages and add console output messages
remove extra carriage returns
1 parent ecc9430 commit a0c94cb

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

mithril-client-cli/src/commands/tools/snapshot_converter.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,31 @@ impl SnapshotConverterCommand {
112112
distribution_dir.display()
113113
)
114114
})?;
115-
116115
let archive_path = Self::download_cardano_node_distribution(
117116
ReqwestGitHubApiClient::new()?,
118117
ReqwestHttpDownloader::new()?,
119118
&self.cardano_node_version,
120119
&distribution_dir,
121120
)
122121
.await
123-
.with_context(|| {
124-
"Failed to download 'snapshot-converter' binary from Cardano node distribution"
125-
})?;
122+
.with_context(|| "Failed to download Cardano node distribution")?;
126123

124+
println!(
125+
"Unpacking distribution from archive: {}",
126+
archive_path.display()
127+
);
127128
ArchiveUnpacker::default()
128129
.unpack(&archive_path, &distribution_dir)
129130
.with_context(|| {
130131
format!(
131-
"Failed to unpack 'snapshot-converter' binary to directory: {}",
132+
"Failed to unpack distribution to directory: {}",
132133
distribution_dir.display()
133134
)
134135
})?;
136+
println!(
137+
"Distribution unpacked successfully to: {}",
138+
distribution_dir.display()
139+
);
135140

136141
Self::convert_ledger_state_snapshot(
137142
&work_dir,
@@ -186,7 +191,6 @@ impl SnapshotConverterCommand {
186191
.await
187192
.with_context(|| format!("Failed to get release by tag: {}", tag))?,
188193
};
189-
190194
let asset = release
191195
.get_asset_for_os(env::consts::OS)?
192196
.ok_or_else(|| anyhow!("No asset found for platform: {}", env::consts::OS))
@@ -196,7 +200,6 @@ impl SnapshotConverterCommand {
196200
env::consts::OS
197201
)
198202
})?;
199-
200203
let archive_path = http_downloader
201204
.download_file(asset.browser_download_url.parse()?, target_dir, &asset.name)
202205
.await?;
@@ -229,7 +232,6 @@ impl SnapshotConverterCommand {
229232
&copied_snapshot_path,
230233
utxo_hd_flavor,
231234
)?;
232-
233235
let converter_bin =
234236
Self::get_snapshot_converter_binary_path(distribution_dir, env::consts::OS)?;
235237
let config_path =
@@ -284,7 +286,6 @@ impl SnapshotConverterCommand {
284286
target_os: &str,
285287
) -> MithrilResult<PathBuf> {
286288
let base_path = distribution_dir.join(SNAPSHOT_CONVERTER_BIN_DIR);
287-
288289
let binary_name = match target_os {
289290
"linux" | "macos" => SNAPSHOT_CONVERTER_BIN_NAME_UNIX,
290291
"windows" => SNAPSHOT_CONVERTER_BIN_NAME_WINDOWS,
@@ -307,19 +308,16 @@ impl SnapshotConverterCommand {
307308
/// Finds the oldest ledger snapshot (by slot number) in the `ledger/` directory of a Cardano node database.
308309
fn find_oldest_ledger_state_snapshot(db_dir: &Path) -> MithrilResult<PathBuf> {
309310
let ledger_dir = db_dir.join(LEDGER_DIR);
310-
311311
let entries = read_dir(&ledger_dir).with_context(|| {
312312
format!(
313313
"Failed to read ledger state snapshots directory: {}",
314314
ledger_dir.display()
315315
)
316316
})?;
317-
318317
let mut min_slot: Option<(u64, PathBuf)> = None;
319318

320319
for entry in entries {
321320
let entry = entry?;
322-
323321
let slot = match Self::extract_slot_number(&entry.path()) {
324322
Ok(number) => number,
325323
Err(_) => continue,
@@ -365,7 +363,6 @@ impl SnapshotConverterCommand {
365363
input_snapshot.display()
366364
)
367365
})?;
368-
369366
let converted_snapshot_path = snapshots_dir.join(format!(
370367
"{}_{}",
371368
slot_number,
@@ -379,7 +376,6 @@ impl SnapshotConverterCommand {
379376
let file_name = path
380377
.file_name()
381378
.ok_or_else(|| anyhow!("No filename in path: {}", path.display()))?;
382-
383379
let file_name_str = file_name
384380
.to_str()
385381
.ok_or_else(|| anyhow!("Invalid UTF-8 in path filename: {:?}", file_name))?;
@@ -400,30 +396,25 @@ impl SnapshotConverterCommand {
400396
ledger_dir.display(),
401397
converted_snapshot_path.display()
402398
);
403-
404399
let filename = converted_snapshot_path
405400
.file_name()
406401
.ok_or_else(|| anyhow!("Missing filename in converted snapshot path"))?
407402
.to_string_lossy();
408-
409403
let (slot_number, _) = filename
410404
.split_once('_')
411405
.ok_or_else(|| anyhow!("Invalid converted snapshot name format: {}", filename))?;
412-
413406
remove_dir_all(&ledger_dir).with_context(|| {
414407
format!(
415408
"Failed to remove old ledger state snapshot directory: {}",
416409
ledger_dir.display()
417410
)
418411
})?;
419-
420412
create_dir(&ledger_dir).with_context(|| {
421413
format!(
422414
"Failed to recreate ledger state snapshot directory: {}",
423415
ledger_dir.display()
424416
)
425417
})?;
426-
427418
let destination = ledger_dir.join(slot_number);
428419
rename(converted_snapshot_path, &destination).with_context(|| {
429420
format!(

0 commit comments

Comments
 (0)