From 71b11c769dd86ccc85807ba7b6e80115f915d79b Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 7 May 2026 23:07:36 +0900 Subject: [PATCH] Fix incorrect error location when R\F\Exception is thrown from inside an event handler --- classes/module/ModuleHandler.class.php | 2 ++ classes/module/ModuleObject.class.php | 8 ++++++++ common/framework/Exception.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/classes/module/ModuleHandler.class.php b/classes/module/ModuleHandler.class.php index 1d8acd7fe..53d3bca1d 100644 --- a/classes/module/ModuleHandler.class.php +++ b/classes/module/ModuleHandler.class.php @@ -1355,6 +1355,7 @@ class ModuleHandler extends Handler catch (Rhymix\Framework\Exception $e) { $output = new BaseObject(-2, $e->getMessage()); + $output->add('rx_error_location', $e->getUserFileAndLine()); } if ($trigger_name !== 'common.flushDebugInfo') @@ -1391,6 +1392,7 @@ class ModuleHandler extends Handler catch (Rhymix\Framework\Exception $e) { $output = new BaseObject(-2, $e->getMessage()); + $output->add('rx_error_location', $e->getUserFileAndLine()); } if ($trigger_name !== 'common.writeSlowlog') diff --git a/classes/module/ModuleObject.class.php b/classes/module/ModuleObject.class.php index 687c07bad..97a1b8049 100644 --- a/classes/module/ModuleObject.class.php +++ b/classes/module/ModuleObject.class.php @@ -805,6 +805,10 @@ class ModuleObject extends BaseObject { $this->setError($triggerOutput->getError()); $this->setMessage($triggerOutput->getMessage()); + if ($triggerOutput->get('rx_error_location')) + { + $this->add('rx_error_location', $triggerOutput->get('rx_error_location')); + } return FALSE; } @@ -846,6 +850,10 @@ class ModuleObject extends BaseObject { $this->setError($triggerOutput->getError()); $this->setMessage($triggerOutput->getMessage()); + if ($triggerOutput->get('rx_error_location')) + { + $this->add('rx_error_location', $triggerOutput->get('rx_error_location')); + } return false; } diff --git a/common/framework/Exception.php b/common/framework/Exception.php index 6cd07d412..89b1a6739 100644 --- a/common/framework/Exception.php +++ b/common/framework/Exception.php @@ -19,6 +19,11 @@ class Exception extends \Exception public function getUserFileAndLine(): string { $regexp = '!^' . preg_quote(\RX_BASEDIR, '!') . '(?:classes|common)/!'; + if (!preg_match($regexp, $this->getFile())) + { + return $this->getFile() . ':' . $this->getLine(); + } + $trace = $this->getTrace(); foreach ($trace as $frame) {