forked from getsentry/magento-amg-sentry-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenmage.diff
354 lines (343 loc) · 16.7 KB
/
openmage.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# multiparts diff for OpenMage 20.3.0
# first this is 3679
diff --git a/app/Mage.php b/app/Mage.php
index dee273c2d3e..a478f86cb56 100644
--- a/app/Mage.php
+++ b/app/Mage.php
@@ -968,21 +968,61 @@
public static function printException(Throwable $e, $extra = '')
{
if (self::$_isDeveloperMode) {
- print '<pre>';
-
+ if (PHP_SAPI != 'cli') {
+ print '<pre style="white-space:pre-wrap;">';
+ }
if (!empty($extra)) {
print $extra . "\n\n";
}
-
- print $e->getMessage() . "\n\n";
- print $e->getTraceAsString();
- print '</pre>';
+ print get_class($e) . ': ' . $e->getMessage() . "\n\n";
+ if (PHP_SAPI != 'cli') {
+ $file = $e->getFile();
+ $line = $e->getLine();
+ if (!empty($_SERVER['MAGE_VSCODE_LINKS']) || !empty($_ENV['MAGE_VSCODE_LINKS'])) {
+ // https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls
+ print preg_replace_callback('#(\#\d+ )([^(]+)\((\d+)\): #', static function ($data) {
+ return
+ $data[1] .
+ '<a href="vscode://file/' . $data[2] . ':' . $data[3] . '">' . $data[2] . '</a>' .
+ '(' . $data[3] . '): ';
+ }, $e->getTraceAsString()) . "\n";
+ print ' thrown in <a href="vscode://file/' . $file . ':' . $line . '"><b>' . $file . '</b></a>';
+ } elseif (!empty($_SERVER['MAGE_PHPSTORM_LINKS']) || !empty($_ENV['MAGE_PHPSTORM_LINKS'])) {
+ // phpstorm doc
+ print preg_replace_callback('#(\#\d+ )([^(]+)\((\d+)\): #', static function ($data) {
+ return
+ $data[1] .
+ '<a href="phpstorm://open?url=file:/' . $data[2] . '&line=' . $data[3] . '">' . $data[2] . '</a>' .
+ '(' . $data[3] . '): ';
+ }, $e->getTraceAsString()) . "\n";
+ print ' thrown in <a href="phpstorm://open?url=file:/' . $file . '&line=' . $line . '"><b>' . $file . '</b></a>';
+ } elseif (!empty($_SERVER['MAGE_OPENFILEEDITOR_LINKS']) || !empty($_ENV['MAGE_OPENFILEEDITOR_LINKS'])) {
+ // https://github.com/luigifab/webext-openfileeditor
+ print preg_replace_callback('#(\#\d+ )([^(]+)\((\d+)\): #', static function ($data) {
+ return
+ $data[1] .
+ '<span class="openfileeditor" data-line="' . $data[3] . '">' . $data[2] . '</span>' .
+ '(' . $data[3] . '): ';
+ }, $e->getTraceAsString()) . "\n";
+ print ' thrown in <span class="openfileeditor" data-line="' . $line . '"><b>' . $file . '</b></span>';
+ } else {
+ print $e->getTraceAsString() . "\n";
+ print ' thrown in <b>' . $file . '</b>';
+ }
+ print ' on line <b>' . $line . '</b>' . "\n";
+ } else {
+ print $e->getTraceAsString() . "\n";
+ print ' thrown in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n";
+ }
+ if (PHP_SAPI != 'cli') {
+ print '</pre>';
+ }
} else {
$reportData = [
- (!empty($extra) ? $extra . "\n\n" : '') . $e->getMessage(),
- $e->getTraceAsString()
+ (empty($extra) ? '' : $extra . "\n\n") . get_class($e) . ': ' . $e->getMessage(),
+ $e->getTraceAsString() . "\n" .
+ ' thrown in ' . $e->getFile() . ' on line ' . $e->getLine()
];
-
// retrieve server data
if (isset($_SERVER['REQUEST_URI'])) {
$reportData['url'] = $_SERVER['REQUEST_URI'];
@@ -990,7 +1030,6 @@
if (isset($_SERVER['SCRIPT_NAME'])) {
$reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
}
-
// attempt to specify store as a skin
try {
$storeCode = self::app()->getStore()->getCode();
diff --git a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
index 5ad0ad18ad8..06fe7c70af8 100644
--- a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
+++ b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
@@ -33,6 +33,7 @@
* @param int $errorCode
* @param string $errorMessage
* @param string $errorFile
+ * @param int $errLine
* @return bool
*/
public function handlePhpError($errorCode, $errorMessage, $errorFile, $errLine)
diff --git a/app/code/core/Mage/Core/Block/Template.php b/app/code/core/Mage/Core/Block/Template.php
index 2598f3304a1..18725c4c0f8 100644
--- a/app/code/core/Mage/Core/Block/Template.php
+++ b/app/code/core/Mage/Core/Block/Template.php
@@ -253,15 +253,50 @@
<div style="position:relative; border:1px dotted {$cacheHintStatusColor}; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;">
<div style="position:absolute; left:0; top:0; padding:2px 5px; background:{$cacheHintStatusColor}; color:white; font:normal 11px Arial;
text-align:left !important; z-index:998;text-transform: none;" onmouseover="this.style.zIndex='999'"
-onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
+onmouseout="this.style.zIndex='998'" title="{$fileName}">
HTML;
+ if (!empty($_SERVER['MAGE_VSCODE_LINKS']) || !empty($_ENV['MAGE_VSCODE_LINKS'])) {
+ // https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls
+ echo '<a href="vscode://file/' . $this->_viewDir . DS . $fileName . '">' . $fileName . '</a></div>';
+ } elseif (!empty($_SERVER['MAGE_PHPSTORM_LINKS']) || !empty($_ENV['MAGE_PHPSTORM_LINKS'])) {
+ // phpstorm doc
+ echo '<a href="phpstorm://open?url=file:/' . $this->_viewDir . DS . $fileName . '">' . $fileName . '</a></div>';
+ } elseif (!empty($_SERVER['MAGE_OPENFILEEDITOR_LINKS']) || !empty($_ENV['MAGE_OPENFILEEDITOR_LINKS'])) {
+ // https://github.com/luigifab/webext-openfileeditor
+ echo '<span class="openfileeditor" data-file="' . $this->_viewDir . DS . $fileName . '">' . $fileName . '</span></div>';
+ } else {
+ echo $fileName . '</div>';
+ }
+
if (Mage::app()->getStore()->isAdmin() ? self::$_showTemplateHintsBlocksAdmin : self::$_showTemplateHintsBlocks) {
$thisClass = get_class($this);
echo <<<HTML
<div style="position:absolute; right:0; top:0; padding:2px 5px; background:{$cacheHintStatusColor}; color:blue; font:normal 11px Arial;
text-align:left !important; z-index:998;text-transform: none;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
-title="{$thisClass}">{$thisClass}</div>
+title="{$thisClass}">
HTML;
+ try {
+ if (!empty($_SERVER['MAGE_VSCODE_LINKS']) || !empty($_ENV['MAGE_VSCODE_LINKS'])) {
+ $reflector = new ReflectionClass($thisClass);
+ $fileClass = $reflector->getFileName();
+ // https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls
+ echo '<a href="vscode://file/' . $fileClass . '">' . $thisClass . '</a></div>';
+ } elseif (!empty($_SERVER['MAGE_PHPSTORM_LINKS']) || !empty($_ENV['MAGE_PHPSTORM_LINKS'])) {
+ $reflector = new ReflectionClass($thisClass);
+ $fileClass = $reflector->getFileName();
+ // phpstorm doc
+ echo '<a href="phpstorm://open?url=file:/' . $fileClass . '">' . $thisClass . '</a></div>';
+ } elseif (!empty($_SERVER['MAGE_OPENFILEEDITOR_LINKS']) || !empty($_ENV['MAGE_OPENFILEEDITOR_LINKS'])) {
+ $reflector = new ReflectionClass($thisClass);
+ $fileClass = $reflector->getFileName();
+ // https://github.com/luigifab/webext-openfileeditor
+ echo '<span class="openfileeditor" data-file="' . $fileClass . '">' . $thisClass . '</span></div>';
+ } else {
+ echo $thisClass . '</div>';
+ }
+ } catch (Throwable $t) {
+ echo $thisClass . '</div>';
+ }
}
}
diff --git a/app/code/core/Mage/Core/functions.php b/app/code/core/Mage/Core/functions.php
index d643769e7f2..79cbc410642 100644
--- a/app/code/core/Mage/Core/functions.php
+++ b/app/code/core/Mage/Core/functions.php
@@ -179,11 +179,10 @@
break;
}
- $errorMessage .= ": {$errstr} in {$errfile} on line {$errline}";
if (Mage::getIsDeveloperMode()) {
- throw new Exception($errorMessage);
+ Mage::printException(new ErrorException($errorMessage . ' ' . $errstr, 0, $errno, $errfile, $errline));
} else {
- Mage::log($errorMessage, Zend_Log::ERR);
+ Mage::log($errorMessage . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline, Zend_Log::ERR);
}
}
diff --git a/app/code/core/Mage/Cron/Model/Observer.php b/app/code/core/Mage/Cron/Model/Observer.php
index fa1ee0b18c8..8ef37a6bfe5 100644
--- a/app/code/core/Mage/Cron/Model/Observer.php
+++ b/app/code/core/Mage/Cron/Model/Observer.php
@@ -324,7 +324,8 @@
->setFinishedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT));
} catch (Exception $e) {
$schedule->setStatus($errorStatus)
- ->setMessages($e->__toString());
+ ->setMessages(get_class($e) . ': ' . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n" .
+ ' thrown in ' . $e->getFile() . ' on line ' . $e->getLine());
}
if ($schedule->getIsError()) {
# multiparts diff for OpenMage 20.3.0
# secondly this is for sentry
diff --git a/app/Mage.php b/app/Mage.php
index 1f50465e73..65ed72cb2b 100644
--- a/app/Mage.php
+++ b/app/Mage.php
@@ -27,6 +27,7 @@
if (!empty($_SERVER['MAGE_IS_DEVELOPER_MODE']) || !empty($_ENV['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
+ error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('error_prepend_string', '<pre>');
ini_set('error_append_string', '</pre>');
@@ -930,8 +931,7 @@
$message = addcslashes($message, '<?');
$loggers[$file]->log($message, $level);
- } catch (Exception $e) {
- }
+ } catch (Exception $e) { }
}
/**
@@ -945,7 +945,16 @@
return;
}
$file = self::getStoreConfig('dev/log/exception_file');
- self::log("\n" . $e->__toString(), Zend_Log::ERR, $file);
+ self::log(
+ (self::$_isDeveloperMode ? 'isDeveloperMode:on ' : 'isDeveloperMode:off ') .
+ (self::getStoreConfigFlag('dev/sentry/active') ? 'sentry:on' : 'sentry:off') .
+ "\n" . $e->getMessage() . "\n" . $e->getTraceAsString() .
+ "\n" . ' thrown in ' . $e->getFile() . ' on line ' . $e->getLine(),
+ Zend_Log::ERR, $file);
+ if (!self::$_isDeveloperMode) {
+ global $sentry;
+ $sentry->captureException($e, null, ['source' => 'mage:logException']);
+ }
}
/**
@@ -975,10 +984,17 @@
*
* @param Throwable $e
*/
- public static function printException(Throwable $e, $extra = '')
+ public static function printException(Throwable $e, $extra = '', $source = '')
{
+ try {
+ while (ob_get_level() > 0) {
+ ob_end_clean();
+ }
+ } catch (Exception $e) { }
+
if (self::$_isDeveloperMode) {
if (PHP_SAPI != 'cli') {
+ @http_response_code(500); // @todo this prevent display of ajax grid error
print '<pre style="white-space:pre-wrap;">';
}
if (!empty($extra)) {
@@ -1024,6 +1040,7 @@
print $e->getTraceAsString() . "\n";
print ' thrown in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n";
}
+ print ' catched by Mage::printException()' . $source . ' at ' . date('c') . "\n";
if (PHP_SAPI != 'cli') {
print '</pre>';
}
@@ -1031,7 +1048,8 @@
$reportData = [
(empty($extra) ? '' : $extra . "\n\n") . get_class($e) . ': ' . $e->getMessage(),
$e->getTraceAsString() . "\n" .
- ' thrown in ' . $e->getFile() . ' on line ' . $e->getLine()
+ ' thrown in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n" .
+ ' catched by Mage::printException()' . $source . ' at ' . date('c')
];
// retrieve server data
if (isset($_SERVER['REQUEST_URI'])) {
@@ -1044,8 +1062,7 @@
try {
$storeCode = self::app()->getStore()->getCode();
$reportData['skin'] = $storeCode;
- } catch (Exception $e) {
- }
+ } catch (Exception $e) { }
require_once(self::getBaseDir() . DS . 'errors' . DS . 'report.php');
}
diff --git a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
index 5bdec0e513..0415b2db42 100644
--- a/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
+++ b/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
@@ -36,9 +36,11 @@
* @param int $errLine
* @return bool
*/
- public function handlePhpError($errorCode, $errorMessage, $errorFile, $errLine)
+ public function handlePhpError($errorCode, $errorMessage, $errorFile, $errLine, $context = [])
{
Mage::log($errorMessage . ' in ' . $errorFile . ' on line ' . $errLine, Zend_Log::ERR);
+ global $sentry;
+ $sentry->handleError($errorCode, $errorMessage, $errorFile, $errLine, $context);
if (in_array($errorCode, [E_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR])) {
$this->_fault('internal');
}
diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php
index d44240102c..52c41ab26f 100644
--- a/app/code/core/Mage/Core/Model/App.php
+++ b/app/code/core/Mage/Core/Model/App.php
@@ -516,9 +516,17 @@
$this->_checkCookieStore($scopeType);
$this->_checkGetStore($scopeType);
}
- $this->_useSessionInUrl = $this->getStore()->getConfig(
- Mage_Core_Model_Session_Abstract::XML_PATH_USE_FRONTEND_SID
- );
+
+ // @see https://github.com/luigifab/openmage-sentry
+ $store = $this->getStore();
+ global $sentry;
+ if (!$sentry) {
+ $sentry = new Luigifab_Sentry_Model_Client();
+ $sentry->initHandler($store);
+ }
+
+ $this->_useSessionInUrl = $store->getConfig(Mage_Core_Model_Session_Abstract::XML_PATH_USE_FRONTEND_SID);
+
return $this;
}
diff --git a/app/code/core/Mage/Core/Model/Email/Template/Filter.php b/app/code/core/Mage/Core/Model/Email/Template/Filter.php
index ea1cc4871e..4db12d177f 100644
--- a/app/code/core/Mage/Core/Model/Email/Template/Filter.php
+++ b/app/code/core/Mage/Core/Model/Email/Template/Filter.php
@@ -549,6 +549,9 @@
try {
$value = parent::filter($value);
} catch (Exception $e) {
+ if (Mage::getIsDeveloperMode()) {
+ throw $e;
+ }
$value = '';
Mage::logException($e);
}
@@ -569,6 +572,9 @@
try {
$result = parent::_getVariable($value, $default);
} catch (Exception $e) {
+ if (Mage::getIsDeveloperMode()) {
+ throw $e;
+ }
$result = '';
Mage::logException($e);
}
diff --git a/app/code/core/Mage/Core/functions.php b/app/code/core/Mage/Core/functions.php
index a9ce749a80..5b59931b5e 100644
--- a/app/code/core/Mage/Core/functions.php
+++ b/app/code/core/Mage/Core/functions.php
@@ -168,7 +168,7 @@
}
if (Mage::getIsDeveloperMode()) {
- Mage::printException(new ErrorException($errorMessage . ' ' . $errstr, 0, $errno, $errfile, $errline));
+ Mage::printException(new ErrorException($errorMessage . ' ' . $errstr, 0, $errno, $errfile, $errline), '', ' via mageCoreErrorHandler()');
} else {
Mage::log($errorMessage . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline, Zend_Log::ERR);
}