]> git.wh0rd.org - tt-rss.git/blame - include/errorhandler.php
bump VERSION_STATIC due to Dojo changes
[tt-rss.git] / include / errorhandler.php
CommitLineData
889a5f9f 1<?php
b8619f8d
AD
2function format_backtrace($trace) {
3 $rv = "";
4 $idx = 1;
5
6 if (is_array($trace)) {
7 foreach ($trace as $e) {
8 if (isset($e["file"]) && isset($e["line"])) {
9 $fmt_args = [];
10
11 if (is_array($e["args"])) {
12 foreach ($e["args"] as $a) {
13 if (!is_object($a)) {
14 array_push($fmt_args, $a);
15 } else {
16 array_push($fmt_args, "[" . get_class($a) . "]");
17 }
18 }
19 }
20
21 $filename = str_replace(dirname(__DIR__) . "/", "", $e["file"]);
22
23 $rv .= sprintf("%d. %s(%s): %s(%s)\n",
24 $idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args));
25
26 $idx++;
27 }
28 }
29 }
30
31 return $rv;
32}
33
889a5f9f
AD
34function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
35 global $logger;
36
eefaa2df 37 if (error_reporting() == 0 || !$errno) return false;
7a51032c 38
4e53956a 39 $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1);
889a5f9f 40
b8619f8d 41 $context = format_backtrace(debug_backtrace());
cc43e19b 42 $errstr = truncate_middle($errstr, 16384, " (...) ");
475d7628 43
15d52d51
AD
44 if (class_exists("Logger"))
45 return Logger::get()->log_error($errno, $errstr, $file, $line, $context);
889a5f9f
AD
46}
47
48function ttrss_fatal_handler() {
49 global $logger;
475d7628 50 global $last_query;
889a5f9f 51
889a5f9f
AD
52 $error = error_get_last();
53
54 if ($error !== NULL) {
77be1217 55 $errno = $error["type"];
889a5f9f
AD
56 $file = $error["file"];
57 $line = $error["line"];
58 $errstr = $error["message"];
59
eefaa2df
AD
60 if (!$errno) return false;
61
b8619f8d 62 $context = format_backtrace(debug_backtrace());
889a5f9f 63
4e53956a 64 $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1);
889a5f9f 65
475d7628
AD
66 if ($last_query) $errstr .= " [Last query: $last_query]";
67
15d52d51
AD
68 if (class_exists("Logger"))
69 return Logger::get()->log_error($errno, $errstr, $file, $line, $context);
889a5f9f 70 }
aca75cb5
AD
71
72 return false;
889a5f9f
AD
73}
74
7329ab2d
AD
75register_shutdown_function('ttrss_fatal_handler');
76set_error_handler('ttrss_error_handler');
889a5f9f 77?>