mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Display filename and line of user code when Rhymix\Framework\Exception is thrown
This commit is contained in:
parent
c213652ccd
commit
d544365399
2 changed files with 24 additions and 3 deletions
|
|
@ -235,7 +235,7 @@ class ModuleObject extends BaseObject
|
||||||
catch (Rhymix\Framework\Exception $e)
|
catch (Rhymix\Framework\Exception $e)
|
||||||
{
|
{
|
||||||
$this->stop($e->getMessage(), -2);
|
$this->stop($e->getMessage(), -2);
|
||||||
$this->add('rx_error_location', $e->getFile() . ':' . $e->getLine());
|
$this->add('rx_error_location', $e->getUserFileAndLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -857,8 +857,7 @@ class ModuleObject extends BaseObject
|
||||||
catch (Rhymix\Framework\Exception $e)
|
catch (Rhymix\Framework\Exception $e)
|
||||||
{
|
{
|
||||||
$output = new BaseObject(-2, $e->getMessage());
|
$output = new BaseObject(-2, $e->getMessage());
|
||||||
$location = $e->getFile() . ':' . $e->getLine();
|
$output->add('rx_error_location', $e->getUserFileAndLine());
|
||||||
$output->add('rx_error_location', $location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger after specific action
|
// Trigger after specific action
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,27 @@ namespace Rhymix\Framework;
|
||||||
*/
|
*/
|
||||||
class Exception extends \Exception
|
class Exception extends \Exception
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Get the file and line, skipping Rhymix framework files.
|
||||||
|
*
|
||||||
|
* This can be more helpful than just using getFile() and getLine()
|
||||||
|
* when the exception is thrown from a Rhymix framework file
|
||||||
|
* but the actual error is caused by a module or theme.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserFileAndLine(): string
|
||||||
|
{
|
||||||
|
$regexp = '!^' . preg_quote(\RX_BASEDIR, '!') . '(?:classes|common)/!';
|
||||||
|
$trace = $this->getTrace();
|
||||||
|
foreach ($trace as $frame)
|
||||||
|
{
|
||||||
|
if (!preg_match($regexp, $frame['file']))
|
||||||
|
{
|
||||||
|
return $frame['file'] . ':' . $frame['line'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getFile() . ':' . $this->getLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue