T-013: Fehlermeldungen — Job-Fehler statt Zusammenfassung (z.B. 'is not downloadable')
This commit is contained in:
@ -365,7 +365,7 @@ fn run_download(mgr: &DownloadMgr, asin: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let aaxc = find_any_aaxc(&dir).or_else(|| find_any_aaxc(&dir));
|
let aaxc = find_any_aaxc(&dir);
|
||||||
let final_bytes = current_bytes(&dir);
|
let final_bytes = current_bytes(&dir);
|
||||||
let ok = aaxc
|
let ok = aaxc
|
||||||
.and_then(|p| fs::metadata(&p).ok())
|
.and_then(|p| fs::metadata(&p).ok())
|
||||||
@ -375,15 +375,36 @@ fn run_download(mgr: &DownloadMgr, asin: &str) {
|
|||||||
if ok {
|
if ok {
|
||||||
mgr.finish(asin, DlStatus::Done, final_bytes, String::new());
|
mgr.finish(asin, DlStatus::Done, final_bytes, String::new());
|
||||||
} else {
|
} else {
|
||||||
let msg = if stderr_text.trim().is_empty() {
|
let msg = pick_download_error(&stderr_text);
|
||||||
"Download endete ohne vollständige AAXC-Datei".to_string()
|
|
||||||
} else {
|
|
||||||
stderr_text.lines().last().unwrap_or("unbekannter Fehler").to_string()
|
|
||||||
};
|
|
||||||
mgr.finish(asin, DlStatus::Failed, final_bytes, msg);
|
mgr.finish(asin, DlStatus::Failed, final_bytes, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sucht die aufschlussreichste Zeile aus dem stderr-Fehlerprotokoll:
|
||||||
|
/// bevorzugt „error: <job> failed for …“ (Enzeljob-Kontext), sonst letzte
|
||||||
|
/// „error:“-Zeile als Fallback. Zusammenfassung-Zeilen („1 job(s) failed“)
|
||||||
|
/// sollen nicht als Meldung landen.
|
||||||
|
fn pick_download_error(stderr: &str) -> String {
|
||||||
|
let lines: Vec<&str> = stderr.lines().filter(|l| !l.trim().is_empty()).collect();
|
||||||
|
if let Some(job_line) = lines
|
||||||
|
.iter()
|
||||||
|
.find(|l| l.starts_with("error:") && l.contains("failed for"))
|
||||||
|
{
|
||||||
|
return job_line.trim_start_matches("error: ").to_string();
|
||||||
|
}
|
||||||
|
if let Some(err_line) = lines
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.find(|l| l.starts_with("error:") && !l.contains("job(s) failed"))
|
||||||
|
{
|
||||||
|
return err_line.trim_start_matches("error: ").to_string();
|
||||||
|
}
|
||||||
|
if let Some(last) = lines.last() {
|
||||||
|
return last.to_string();
|
||||||
|
}
|
||||||
|
"Download endete ohne vollständige AAXC-Datei".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/// Größe der größten AAXC/AXP-Datei im Job-Verzeichnis.
|
/// Größe der größten AAXC/AXP-Datei im Job-Verzeichnis.
|
||||||
fn current_bytes(dir: &Path) -> u64 {
|
fn current_bytes(dir: &Path) -> u64 {
|
||||||
let mut best = 0u64;
|
let mut best = 0u64;
|
||||||
@ -425,6 +446,19 @@ fn find_any_aaxc(dir: &Path) -> Option<PathBuf> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pick_download_error_waehlt_job_fehler() {
|
||||||
|
let s = "File x.jpg downloaded\nChapter file saved\nerror: download_aaxc failed for Einhornprinz (B015HG6T6A): AudibleCliException: is not downloadable.\nThe download ended with the following result:\nerror: 1 job(s) failed. Use --ignore-errors to download the rest anyway";
|
||||||
|
assert_eq!(
|
||||||
|
pick_download_error(s),
|
||||||
|
"download_aaxc failed for Einhornprinz (B015HG6T6A): AudibleCliException: is not downloadable."
|
||||||
|
);
|
||||||
|
// Fallback: keine Job-Zeile, aber error:-Zeile
|
||||||
|
assert_eq!(pick_download_error("error: 401 unauthorized\nerror: 1 job(s) failed"), "401 unauthorized");
|
||||||
|
// gar nichts da
|
||||||
|
assert_eq!(pick_download_error(""), "Download endete ohne vollständige AAXC-Datei");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dl_item_serde_status() {
|
fn dl_item_serde_status() {
|
||||||
let it = DlItem {
|
let it = DlItem {
|
||||||
|
|||||||
Reference in New Issue
Block a user