From a38ed045e9981664d90c05ab43ab4ab6026eb31b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 30 Aug 2026 23:57:25 +0900 Subject: feat(plugin): carry an exception's class and state across the boundary A Rust-side failure reached plugin code as a RuntimeException whose message carried the name of the call that failed, so `catch (TransportException $e)` never matched and the status code the plugin branches on was gone. The Throw frame now names the class the exception was thrown as and carries the state that class declares beyond message and code. \Shirabe\MaterializedThrowable rebuilds it in the child: `new $class($message, $code)` for a class whose constructor has \Exception's shape, then the properties by reflection. A class the child cannot build that way keeps the RuntimeException shape. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-rpc/php/worker.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'crates/shirabe-php-rpc/php/worker.php') diff --git a/crates/shirabe-php-rpc/php/worker.php b/crates/shirabe-php-rpc/php/worker.php index bc10c2de..defa4fb5 100644 --- a/crates/shirabe-php-rpc/php/worker.php +++ b/crates/shirabe-php-rpc/php/worker.php @@ -337,10 +337,13 @@ final class ShirabeRpcRuntime $outParams = self::fromWire($fields[1] ?? []); return self::fromWire($fields[0]); } - [$class, $message, $code] = $fields; - // TODO(plugin): reconstruct the original exception class instead of collapsing - // everything to RuntimeException. - throw new RuntimeException($message, (int) $code); + [$class, $message, $code, $properties] = $fields; + throw \Shirabe\MaterializedThrowable::revive( + $class, + $message, + (int) $code, + self::fromWire($properties) + ); } self::dispatchRequest($tag, $inId, $payload); } @@ -435,7 +438,9 @@ final class ShirabeRpcRuntime self::writeFrame( SHIRABE_TAG_THROW, $corrId, - serialize([get_class($e), $e->getMessage(), (int) $e->getCode()]) + // TODO(plugin): the properties field is empty in this direction; no Rust-side + // consumer rebuilds a ported exception from a Throw frame yet. + serialize([get_class($e), $e->getMessage(), (int) $e->getCode(), []]) ); } } -- cgit v1.3.1-4-g156e