diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 00:10:37 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 00:14:34 +0900 |
| commit | 5ffe30e9962524415cd12b31e094bf75ca4e4908 (patch) | |
| tree | b095791bb9cd91105771410183a6ca875a8a0107 /crates/shirabe/src/package | |
| parent | c74f4314853c0e7283691fdd4d0dec27c1199537 (diff) | |
| download | php-shirabe-5ffe30e9962524415cd12b31e094bf75ca4e4908.tar.gz php-shirabe-5ffe30e9962524415cd12b31e094bf75ca4e4908.tar.zst php-shirabe-5ffe30e9962524415cd12b31e094bf75ca4e4908.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package')
| -rw-r--r-- | crates/shirabe/src/package/archiver/phar_archiver.rs | 14 |
1 files changed, 10 insertions, 4 deletions
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::<UnexpectedValueException>() 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() }) |
