aboutsummaryrefslogtreecommitdiff
path: root/lib/error.php
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2022-07-08 20:39:13 +0200
committerGravatar GitHub <noreply@github.com> 2022-07-08 20:39:13 +0200
commitabc4af43b3d15c00536f79afb2b9c8557a58a8e3 (patch)
treeb9c66eeddc5fb7626ce5f4a2b3c747d1132581bc /lib/error.php
parentc992bcc8bf0a5abbc9ea897acc7d98520763313d (diff)
downloadrss-bridge-abc4af43b3d15c00536f79afb2b9c8557a58a8e3.tar.gz
rss-bridge-abc4af43b3d15c00536f79afb2b9c8557a58a8e3.tar.zst
rss-bridge-abc4af43b3d15c00536f79afb2b9c8557a58a8e3.zip
feat: improve error handling (#2902)
Diffstat (limited to 'lib/error.php')
-rw-r--r--lib/error.php31
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);
+}