mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-06-26 07:08:42 +02:00
feat: improve error handling (#2902)
This commit is contained in:
parent
c992bcc8bf
commit
abc4af43b3
10 changed files with 180 additions and 254 deletions
|
@ -79,3 +79,34 @@ function logBridgeError($bridgeName, $code)
|
|||
|
||||
return $report['count'];
|
||||
}
|
||||
|
||||
function create_sane_stacktrace(\Throwable $e): array
|
||||
{
|
||||
$frames = array_reverse($e->getTrace());
|
||||
$frames[] = [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
];
|
||||
$stackTrace = [];
|
||||
foreach ($frames as $i => $frame) {
|
||||
$file = $frame['file'] ?? '(no file)';
|
||||
$line = $frame['line'] ?? '(no line)';
|
||||
$stackTrace[] = sprintf(
|
||||
'#%s %s:%s',
|
||||
$i,
|
||||
trim_path_prefix($file),
|
||||
$line,
|
||||
);
|
||||
}
|
||||
return $stackTrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim path prefix for privacy/security reasons
|
||||
*
|
||||
* Example: "/var/www/rss-bridge/index.php" => "index.php"
|
||||
*/
|
||||
function trim_path_prefix(string $filePath): string
|
||||
{
|
||||
return mb_substr($filePath, mb_strlen(dirname(__DIR__)) + 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue