aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader/download_manager.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/downloader/download_manager.rs')
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 33a555a..b230ae3 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -238,7 +238,6 @@ impl DownloadManager {
}
};
- // TODO(phase-b): use anyhow::Result<Result<T, E>> to model PHP try/catch
let result = match downloader
.download3(package.clone(), &target_dir, prev_package.clone())
.await
@@ -246,21 +245,25 @@ impl DownloadManager {
Ok(r) => r,
Err(e) => {
// PHP closure handleError: rethrow if not RuntimeException or if IrrecoverableDownloadException
- // TODO(phase-b): downcast for instanceof checks
- let is_runtime: bool = todo!("e instanceof RuntimeException");
- let is_irrecoverable: bool =
- todo!("e instanceof IrrecoverableDownloadException");
+ let is_runtime = e.downcast_ref::<RuntimeException>().is_some();
+ let is_irrecoverable =
+ e.downcast_ref::<IrrecoverableDownloadException>().is_some();
if is_runtime && !is_irrecoverable {
if sources.is_empty() {
return Err(e);
}
+ let message = e
+ .downcast_ref::<RuntimeException>()
+ .unwrap()
+ .message
+ .clone();
self.io.write_error3(
&format!(
" <warning>Failed to download {} from {}: {}</warning>",
package.get_pretty_name(),
source,
- e,
+ message,
),
true,
io_interface::NORMAL,
@@ -359,7 +362,6 @@ impl DownloadManager {
let initial_type = self.get_downloader_type(initial_downloader.unwrap());
let target_type = self.get_downloader_type(downloader.unwrap());
if initial_type == target_type {
- // TODO(phase-b): use anyhow::Result<Result<T, E>> to model PHP try/catch
match downloader
.unwrap()
.update(initial.clone(), target.clone(), &target_dir)
@@ -367,13 +369,20 @@ impl DownloadManager {
{
Ok(p) => return Ok(p),
Err(e) => {
- // TODO(phase-b): downcast to RuntimeException
- let _re: &RuntimeException = todo!("downcast e to RuntimeException");
+ // PHP catches only \RuntimeException; other exceptions propagate uncaught.
+ if e.downcast_ref::<RuntimeException>().is_none() {
+ return Err(e);
+ }
if !self.io.is_interactive() {
return Err(e);
}
+ let message = e
+ .downcast_ref::<RuntimeException>()
+ .unwrap()
+ .message
+ .clone();
self.io.write_error3(
- &format!("<error> Update failed ({})</error>", e,),
+ &format!("<error> Update failed ({})</error>", message),
true,
io_interface::NORMAL,
);