diff options
Diffstat (limited to 'crates/shirabe')
| -rw-r--r-- | crates/shirabe/src/downloader/download_manager.rs | 27 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/vcs_downloader.rs | 15 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/installation_manager.rs | 3 | ||||
| -rw-r--r-- | crates/shirabe/src/json/json_file.rs | 13 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/repository_set.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/svn_driver.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/util/github.rs | 1 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http_downloader.rs | 1 |
8 files changed, 57 insertions, 29 deletions
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs index 33a555a..8131bcf 100644 --- a/crates/shirabe/src/downloader/download_manager.rs +++ b/crates/shirabe/src/downloader/download_manager.rs @@ -246,21 +246,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, @@ -367,13 +371,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, ); diff --git a/crates/shirabe/src/downloader/vcs_downloader.rs b/crates/shirabe/src/downloader/vcs_downloader.rs index b09841e..c3a1611 100644 --- a/crates/shirabe/src/downloader/vcs_downloader.rs +++ b/crates/shirabe/src/downloader/vcs_downloader.rs @@ -149,8 +149,9 @@ pub trait VcsDownloader: match attempt { Ok(promise) => return Ok(promise), Err(e) => { - // rethrow phpunit exceptions to avoid hard to debug bug failures - // TODO(phase-b): downcast to PHPUnit\Framework\Exception + // rethrow phpunit exceptions to avoid hard to debug bug failures. + // PHPUnit\Framework\Exception is out of scope (the test framework is not + // ported), so this instanceof check is always false. let is_phpunit_exception = false; if is_phpunit_exception { return Err(e); @@ -265,8 +266,9 @@ pub trait VcsDownloader: match attempt { Ok(_) => break, Err(e) => { - // rethrow phpunit exceptions to avoid hard to debug bug failures - // TODO(phase-b): downcast to PHPUnit\Framework\Exception + // rethrow phpunit exceptions to avoid hard to debug bug failures. + // PHPUnit\Framework\Exception is out of scope (the test framework is not + // ported), so this instanceof check is always false. let is_phpunit_exception = false; if is_phpunit_exception { return Err(e); @@ -344,8 +346,9 @@ pub trait VcsDownloader: break; } Err(e) => { - // rethrow phpunit exceptions to avoid hard to debug bug failures - // TODO(phase-b): downcast to PHPUnit\Framework\Exception + // rethrow phpunit exceptions to avoid hard to debug bug failures. + // PHPUnit\Framework\Exception is out of scope (the test framework is not + // ported), so this instanceof check is always false. let is_phpunit_exception = false; if is_phpunit_exception { return Err(e); diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index b95ad26..073625b 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -208,7 +208,6 @@ impl InstallationManager { let mut batch: IndexMap<i64, Box<dyn OperationInterface>> = IndexMap::new(); for (index, operation) in operations.into_iter().enumerate() { let index = index as i64; - // PHP: $operation instanceof UpdateOperation || $operation instanceof InstallOperation let package: Option<PackageInterfaceHandle> = if let Some(update) = operation.as_update_operation() { Some(update.get_target_package()) @@ -367,7 +366,6 @@ impl InstallationManager { let mut batches: Vec<IndexMap<i64, Box<dyn OperationInterface>>> = vec![]; let mut batch: IndexMap<i64, Box<dyn OperationInterface>> = IndexMap::new(); for (index, operation) in operations { - // PHP: $operation instanceof InstallOperation || $operation instanceof UpdateOperation let package: Option<PackageInterfaceHandle> = if let Some(update) = operation.as_update_operation() { Some(update.get_target_package()) @@ -444,7 +442,6 @@ impl InstallationManager { io_interface::NORMAL, ); } - // PHP: $this->{$opType}($repo, $operation); match op_type.as_str() { "markAliasInstalled" => { let op = operation diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index 2450b0a..364c2b9 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -138,10 +138,15 @@ impl JsonFile { })() { Ok(j) => j, Err(e) => { - // TODO(phase-b): downcast e to TransportException to match the specific catch - let _te: &TransportException = todo!("downcast e to TransportException"); - // PHP: throw new \RuntimeException($e->getMessage(), 0, $e); (rethrow wrapped) - // PHP fallback: throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage()); + // TransportException keeps its message verbatim; any other exception is wrapped + // with the "Could not read" prefix. + if let Some(te) = e.downcast_ref::<TransportException>() { + return Err(RuntimeException { + message: te.message.clone(), + code: 0, + } + .into()); + } return Err(RuntimeException { message: format!("Could not read {}\n\n{}", self.path, e), code: 0, diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs index ac904fc..1323fbd 100644 --- a/crates/shirabe/src/repository/repository_set.rs +++ b/crates/shirabe/src/repository/repository_set.rs @@ -395,12 +395,20 @@ impl RepositorySet { match attempt { Ok(_) => {} Err(e) => { - // TODO(phase-b): downcast e to \Composer\Downloader\TransportException - let _te: &TransportException = todo!("downcast e to TransportException"); + // PHP catches only \Composer\Downloader\TransportException; other + // exceptions propagate uncaught. + if e.downcast_ref::<TransportException>().is_none() { + return Err(e); + } if !ignore_unreachable { return Err(e); } - unreachable_repos.push(e.to_string()); + let message = e + .downcast_ref::<TransportException>() + .unwrap() + .message + .clone(); + unreachable_repos.push(message); } } } diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index a793340..2812c8d 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -184,9 +184,15 @@ impl SvnDriver { let composer: Option<IndexMap<String, PhpMixed>> = match base_result { Ok(c) => c, Err(e) => { - // TODO(phase-b): downcast to TransportException - let _te: &TransportException = todo!("downcast e to TransportException"); - let message = e.to_string(); + // PHP catches only TransportException; other exceptions propagate uncaught. + if e.downcast_ref::<TransportException>().is_none() { + return Err(e); + } + let message = e + .downcast_ref::<TransportException>() + .unwrap() + .message + .clone(); if stripos(&message, "path not found").is_none() && stripos(&message, "svn: warning: W160013").is_none() { diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index c87a83f..650ae33 100644 --- a/crates/shirabe/src/util/github.rs +++ b/crates/shirabe/src/util/github.rs @@ -241,7 +241,6 @@ impl GitHub { { Ok(_) => {} Err(te) => { - // TODO(phase-b): downcast anyhow::Error to TransportException for status code let code = te .downcast_ref::<crate::downloader::TransportException>() .and_then(|t| t.get_status_code()) diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index 166f1f8..89bf0a4 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -792,7 +792,6 @@ impl HttpDownloader { /// /// @return ?string[] pub fn get_exception_hints(e: &anyhow::Error) -> Option<Vec<String>> { - // TODO(phase-b): `$e instanceof TransportException` let e_as_transport: Option<&TransportException> = e.downcast_ref::<TransportException>(); if e_as_transport.is_none() { return None; |
