Skip to content

Commit 19c24b8

Browse files
committed
Ensure error messages appear in stderr output
1 parent 944cf28 commit 19c24b8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/download_sources/apkpure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub async fn list_versions(apps: Vec<(String, Option<String>)>, options: HashMap
201201
_ => {
202202
match output_format {
203203
OutputFormat::Plaintext => {
204-
println!("| Invalid app response for {}. Skipping...", app_id);
204+
eprintln!("| Invalid app response for {}. Skipping...", app_id);
205205
},
206206
OutputFormat::Json => {
207207
let mut app_root = HashMap::new();

src/download_sources/fdroid.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async fn retrieve_index_or_exit(options: &HashMap<&str, &str>, mp: Rc<MultiProgr
174174

175175
fn print_error(err_msg: &str, output_format: OutputFormat) {
176176
match output_format {
177-
OutputFormat::Plaintext => println!("{}", err_msg),
177+
OutputFormat::Plaintext => eprintln!("{}", err_msg),
178178
OutputFormat::Json => println!("{{\"error\":\"{}\"}}", err_msg),
179179
}
180180
}
@@ -194,11 +194,10 @@ pub async fn download_apps(
194194
options: HashMap<&str, &str>,
195195
) {
196196
let mp = Rc::new(MultiProgress::new());
197-
let mp_index = Rc::clone(&mp);
198-
let index = retrieve_index_or_exit(&options, mp_index, OutputFormat::Plaintext).await;
197+
let index = retrieve_index_or_exit(&options, Rc::clone(&mp), OutputFormat::Plaintext).await;
199198

200199
let app_arch = options.get("arch").map(|x| x.to_string());
201-
let (fdroid_apps, repo_address) = match parse_json_for_download_information(index, apps, app_arch.clone()) {
200+
let (fdroid_apps, repo_address) = match parse_json_for_download_information(index, apps, app_arch.clone(), Rc::clone(&mp)) {
202201
Ok((fdroid_apps, repo_address)) => (fdroid_apps, repo_address),
203202
Err(_) => {
204203
println!("Could not parse JSON of F-Droid package index. Exiting.");
@@ -295,7 +294,7 @@ type DownloadInformation = (Vec<(String, Option<String>, String, Vec<u8>)>, Stri
295294
/// flexible enough to parse either, and may work on future index versions as well. Since `sha256`
296295
/// digests are checked before proceeding, I don't foresee this having an insecure failure mode, so
297296
/// checking the index version and making the parsing overly brittle has no substantive advantage.
298-
fn parse_json_for_download_information(index: Value, apps: Vec<(String, Option<String>)>, app_arch: Option<String>) -> Result<DownloadInformation, FDroidError> {
297+
fn parse_json_for_download_information(index: Value, apps: Vec<(String, Option<String>)>, app_arch: Option<String>, mp_log: Rc<MultiProgress>) -> Result<DownloadInformation, FDroidError> {
299298
let index_map = index.as_object().ok_or(FDroidError::Dummy)?;
300299
let repo_address = index_map
301300
.get("repo").ok_or(FDroidError::Dummy)?
@@ -338,7 +337,7 @@ fn parse_json_for_download_information(index: Value, apps: Vec<(String, Option<S
338337
}
339338
}
340339
let arch_str = app_arch.as_ref().map_or("".to_string(), |x| format!(" {}", x));
341-
println!("Could not find version {}{} of {}. Skipping...", app_version.unwrap(), arch_str, app_id);
340+
mp_log.println(format!("Could not find version {}{} of {}. Skipping...", app_version.unwrap(), arch_str, app_id)).unwrap();
342341
return None;
343342
},
344343
Some(Value::Object(app_object)) => {
@@ -380,7 +379,7 @@ fn parse_json_for_download_information(index: Value, apps: Vec<(String, Option<S
380379
}
381380
}
382381
},
383-
_ => println!("Could not find {} in package list. Skipping...", app_id),
382+
_ => mp_log.println(format!("Could not find {} in package list. Skipping...", app_id)).unwrap(),
384383
}
385384
None
386385
}).flatten().collect();
@@ -446,7 +445,7 @@ fn parse_json_display_versions(index: Value, apps: Vec<(String, Option<String>)>
446445
_ => {
447446
match output_format {
448447
OutputFormat::Plaintext => {
449-
println!("| Could not find {} in package list. Skipping...", app_id);
448+
eprintln!("| Could not find {} in package list. Skipping...", app_id);
450449
},
451450
OutputFormat::Json => {
452451
let mut app_root = HashMap::new();

0 commit comments

Comments
 (0)