From f4cad2123b2af0de72bda4ce039e16e74f163f4e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 8 Aug 2026 22:14:12 +0900 Subject: feat(php-shim): give ported exceptions PHP's class hierarchy Ported exceptions were flat structs reached with `downcast_ref`, so Composer's `catch (\RuntimeException $e)` only matched the exact leaf type and `get_class($e)` had nothing to report. Each exception now embeds an instance of the class it extends and travels inside an `AnyThrowable`; `Catch::catch`/`catch_mut` walk that chain, and `PhpClass::php_class_name` yields the PHP FQCN. Dropping the `std::error::Error` impls from the exception types leaves `AnyThrowable` as the only route into an `anyhow::Error`, so the walk cannot be bypassed. A `no_exception_downcast` linter catches the `downcast::()` calls that would now silently answer `None`. Three sites change behavior as a result: the `TransportException` exit-code override reaches `MaxFileSizeExceededException`, the `catch (\LogicException)` in findSimilar() reaches its subclasses, and rendered exception titles carry the real class name rather than a guess. `get_class_err()` is no longer a `todo!()`, which re-enables FilesystemRepositoryTest::testCorruptedRepositoryFile. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/symfony/console/input/input_definition.rs | 120 +++++++++------------ 1 file changed, 50 insertions(+), 70 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs') diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs index eabb7003..bd32a8f9 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs @@ -110,39 +110,30 @@ impl InputDefinition { let argument = std::rc::Rc::new(argument); if self.arguments.contains_key(argument.get_name()) { - return Err(LogicException(shirabe_php_shim::LogicException { - message: format!( - "An argument with name \"{}\" already exists.", - argument.get_name(), - ), - code: 0, - }) + return Err(LogicException::new(format!( + "An argument with name \"{}\" already exists.", + argument.get_name(), + )) .into()); } if let Some(last_array_argument) = &self.last_array_argument { - return Err(LogicException(shirabe_php_shim::LogicException { - message: format!( - "Cannot add a required argument \"{}\" after an array argument \"{}\".", - argument.get_name(), - last_array_argument.get_name(), - ), - code: 0, - }) + return Err(LogicException::new(format!( + "Cannot add a required argument \"{}\" after an array argument \"{}\".", + argument.get_name(), + last_array_argument.get_name(), + )) .into()); } if argument.is_required() && let Some(last_optional_argument) = &self.last_optional_argument { - return Err(LogicException(shirabe_php_shim::LogicException { - message: format!( - "Cannot add a required argument \"{}\" after an optional one \"{}\".", - argument.get_name(), - last_optional_argument.get_name(), - ), - code: 0, - }) + return Err(LogicException::new(format!( + "Cannot add a required argument \"{}\" after an optional one \"{}\".", + argument.get_name(), + last_optional_argument.get_name(), + )) .into()); } @@ -165,13 +156,11 @@ impl InputDefinition { /// Returns an InputArgument by name or by position. pub fn get_argument(&self, name: &PhpMixed) -> anyhow::Result> { if !self.has_argument(name) { - return Err( - InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: format!("The \"{}\" argument does not exist.", name.clone()), - code: 0, - }) - .into(), - ); + return Err(InvalidArgumentException::new(format!( + "The \"{}\" argument does not exist.", + name.clone() + )) + .into()); } match name { @@ -260,17 +249,17 @@ impl InputDefinition { if let Some(existing) = self.options.get(option.get_name()) && !option.equals(existing) { - return Err(LogicException(shirabe_php_shim::LogicException { - message: format!("An option named \"{}\" already exists.", option.get_name()), - code: 0, - }) + return Err(LogicException::new(format!( + "An option named \"{}\" already exists.", + option.get_name() + )) .into()); } if self.negations.contains_key(option.get_name()) { - return Err(LogicException(shirabe_php_shim::LogicException { - message: format!("An option named \"{}\" already exists.", option.get_name()), - code: 0, - }) + return Err(LogicException::new(format!( + "An option named \"{}\" already exists.", + option.get_name() + )) .into()); } @@ -279,13 +268,10 @@ impl InputDefinition { if let Some(existing_name) = self.shortcuts.get(&shortcut) && !option.equals(&self.options[existing_name]) { - return Err(LogicException(shirabe_php_shim::LogicException { - message: format!( - "An option with shortcut \"{}\" already exists.", - shortcut.clone(), - ), - code: 0, - }) + return Err(LogicException::new(format!( + "An option with shortcut \"{}\" already exists.", + shortcut.clone(), + )) .into()); } } @@ -303,10 +289,10 @@ impl InputDefinition { if option.is_negatable() { let negated_name = format!("no-{}", option.get_name()); if self.options.contains_key(&negated_name) { - return Err(LogicException(shirabe_php_shim::LogicException { - message: format!("An option named \"{}\" already exists.", negated_name), - code: 0, - }) + return Err(LogicException::new(format!( + "An option named \"{}\" already exists.", + negated_name + )) .into()); } self.negations @@ -319,13 +305,11 @@ impl InputDefinition { /// Returns an InputOption by name. pub fn get_option(&self, name: &str) -> anyhow::Result> { if !self.has_option(name) { - return Err( - InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: format!("The \"--{}\" option does not exist.", name), - code: 0, - }) - .into(), - ); + return Err(InvalidArgumentException::new(format!( + "The \"--{}\" option does not exist.", + name + )) + .into()); } Ok(std::rc::Rc::clone(&self.options[name])) @@ -374,13 +358,11 @@ impl InputDefinition { /// Returns the InputOption name given a shortcut. pub fn shortcut_to_name(&self, shortcut: &str) -> anyhow::Result { match self.shortcuts.get(shortcut) { - None => Err( - InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: format!("The \"-{}\" option does not exist.", shortcut), - code: 0, - }) - .into(), - ), + None => Err(InvalidArgumentException::new(format!( + "The \"-{}\" option does not exist.", + shortcut + )) + .into()), Some(name) => Ok(name.clone()), } } @@ -388,13 +370,11 @@ impl InputDefinition { /// Returns the InputOption name given a negation. pub fn negation_to_name(&self, negation: &str) -> anyhow::Result { match self.negations.get(negation) { - None => Err( - InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: format!("The \"--{}\" option does not exist.", negation), - code: 0, - }) - .into(), - ), + None => Err(InvalidArgumentException::new(format!( + "The \"--{}\" option does not exist.", + negation + )) + .into()), Some(name) => Ok(name.clone()), } } -- cgit v1.3.1-4-g156e