From 5ffe30e9962524415cd12b31e094bf75ca4e4908 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 00:10:37 +0900 Subject: fix(archiver): narrow PharArchiver's catch to \UnexpectedValueException PharArchiver::archive catches only `\UnexpectedValueException` and wraps it in a `\RuntimeException` naming the target and sources; anything else leaves the method as it was thrown. The port wrapped every error, so the two `\RuntimeException('Can not compress to %s format')` raised inside the `try` came back out with a second message around them and their code replaced. Reading the message and code off the caught exception rather than off whatever arrived also drops the guesswork the old `map_or(0, ..)` had to do. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/package/archiver/phar_archiver.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/src/package') diff --git a/crates/shirabe/src/package/archiver/phar_archiver.rs b/crates/shirabe/src/package/archiver/phar_archiver.rs index 4a41d5a4..ea04a302 100644 --- a/crates/shirabe/src/package/archiver/phar_archiver.rs +++ b/crates/shirabe/src/package/archiver/phar_archiver.rs @@ -4,9 +4,10 @@ use crate::package::archiver::ArchivableFilesFilter; use crate::package::archiver::ArchivableFilesFinder; use crate::package::archiver::ArchiverInterface; use indexmap::IndexMap; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - AnyThrowable, FilesystemIterator, Phar, PharData, RuntimeException, bzcompress, file_exists, - file_put_contents, function_exists, gzcompress, str_repeat, strrpos, unlink, + FilesystemIterator, Phar, PharData, RuntimeException, UnexpectedValueException, bzcompress, + file_exists, file_put_contents, function_exists, gzcompress, str_repeat, strrpos, unlink, }; fn formats() -> IndexMap<&'static str, i64> { @@ -143,11 +144,16 @@ impl ArchiverInterface for PharArchiver { })(); inner.map_err(|e| { + let Some(caught) = e.catch::() else { + return e; + }; let message = format!( "Could not create archive '{}' from '{}': {}", - target_outer, sources, e + target_outer, + sources, + caught.get_message() ); - let code = AnyThrowable::of(e.as_ref()).map_or(0, AnyThrowable::get_code); + let code = caught.get_code(); RuntimeException::with_code_and_previous(message, code, Some(std::sync::Arc::new(e))) .into() }) -- cgit v1.3.1-4-g156e