Skip to content

Commit 5e034ee

Browse files
committed
refactor: improve fetch rootfs manifest file failed error handle
1 parent d29db01 commit 5e034ee

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/actions/onboarding.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,35 @@ fn auto_pick_rootfs(
128128
theme: &dyn dialoguer::theme::Theme,
129129
arch: &str,
130130
) -> Result<(String, Option<String>, bool)> {
131-
let root = pick_latest_rootfs(arch);
131+
match pick_latest_rootfs(arch) {
132+
Ok(rootfs) => {
133+
info!(
134+
"Ciel has picked buildkit for {}, released on {}",
135+
rootfs.arch, rootfs.date
136+
);
137+
Ok((
138+
format!("https://releases.aosc.io/{}", rootfs.path),
139+
Some(rootfs.sha256sum),
140+
false,
141+
))
142+
}
143+
Err(e) => {
144+
if let Some(e) = e.downcast_ref::<ureq::Error>() {
145+
error!("Failed to fetch manifest: {}", e);
146+
std::process::exit(1);
147+
}
132148

133-
if let Ok(rootfs) = root {
134-
info!(
135-
"Ciel has picked buildkit for {}, released on {}",
136-
rootfs.arch, rootfs.date
137-
);
138-
Ok((
139-
format!("https://releases.aosc.io/{}", rootfs.path),
140-
Some(rootfs.sha256sum),
141-
false,
142-
))
143-
} else {
144-
warn!(
145-
"Ciel was unable to find a suitable buildkit release. Please specify the URL manually."
146-
);
147-
let rootfs_url = Input::<String>::with_theme(theme)
148-
.with_prompt("Rootfs URL")
149-
.interact_text()?;
149+
warn!(
150+
"Ciel was unable to find a suitable buildkit release. Please specify the URL manually."
151+
);
150152

151-
let use_tarball = !rootfs_url.ends_with(".squashfs");
153+
let rootfs_url = Input::<String>::with_theme(theme)
154+
.with_prompt("Rootfs URL")
155+
.interact_text()?;
152156

153-
Ok((rootfs_url, None, use_tarball))
157+
let use_tarball = !rootfs_url.ends_with(".squashfs");
158+
159+
Ok((rootfs_url, None, use_tarball))
160+
}
154161
}
155162
}

src/network.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ pub fn pick_latest_rootfs(arch: &str) -> Result<RootFs> {
9999
.collect();
100100

101101
if rootfs.is_empty() {
102-
return Err(anyhow!("No suitable squashfs was found"));
102+
return Err(anyhow!("No suitable squashfs was found").into());
103103
}
104+
104105
rootfs.sort_unstable_by_key(|x| x.date.clone());
105106

106107
Ok(rootfs.last().unwrap().to_owned())

0 commit comments

Comments
 (0)