diff options
Diffstat (limited to 'lib/error.php')
-rw-r--r-- | lib/error.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/error.php b/lib/error.php index b8b2f9af..1a3d294d 100644 --- a/lib/error.php +++ b/lib/error.php @@ -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); +} |