-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexception.php
More file actions
35 lines (28 loc) · 1.13 KB
/
exception.php
File metadata and controls
35 lines (28 loc) · 1.13 KB
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
<?php
require __DIR__.'/api.php';
$databankPath = keyValue('databanks').'/'.keyValue('databank');
// ['map' => 'Tutorial/', ...]
$info = ['ua' => $_SERVER['HTTP_USER_AGENT'] ?? null] + $_REQUEST;
try {
$info['revision'] = trim(file_get_contents("$databankPath/revision.txt"));
} catch (Throwable $e) {}
// ['message' => 'TypeError: foo is undefined', ...]
$exception = json_decode($_REQUEST['exception'], true);
$stack = $exception['error']['stack'] ?? null;
if ($stack) {
$cmd = ['node', 'exception-map.js'];
$cmd[] = "$databankPath/herowo.min.js.map";
$descr = [['pipe', 'r'], ['pipe', 'w']];
try {
$proc = proc_open(join(' ', array_map('escapeshellarg', $cmd)), $descr, $pipes, __DIR__, null, ['bypass_shell' => true]);
fwrite($pipes[0], $stack);
fclose($pipes[0]);
$exception = ['mapped' => "\n".stream_get_contents($pipes[1])] + $exception;
fclose($pipes[1]);
proc_close($proc);
} catch (Throwable $e) {}
}
mailAdmin('exception',
'Exception '.substr($info['revision'] ?? '', 0, 6).': '.($exception['message'] ?? ''),
var_export(compact('exception') + $info, true));
http_response_code(204);