-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathRollbarError.php
More file actions
65 lines (56 loc) · 1.6 KB
/
RollbarError.php
File metadata and controls
65 lines (56 loc) · 1.6 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
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
<?php
namespace Drupal\server_rollbar_test\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\node\NodeInterface;
/**
* Rollbar error.
*/
final class RollbarError extends ControllerBase {
/**
* Get invalid data from a node.
*/
protected function debug(NodeInterface $node, int $count = 0, array $data = []) {
// Increase complexity by adding nested arrays and objects.
if ($count < 500) {
$new_data = [
'int' => random_int(1, PHP_INT_MAX),
'nested_array' => array_fill(0, 10, str_repeat('x', 1000)),
'node_label' => $node->label(),
'object' => (object) [
'id' => bin2hex(random_bytes(16)),
'timestamp' => time(),
'random' => random_int(1, PHP_INT_MAX),
'deep_nested' => new \stdClass(),
],
];
// Recurse to build deeper structure.
return $this->debug($node, $count + 1, array_merge($data, [$new_data]));
}
// @phpstan-ignore-next-line
return $node->label() . $f;
}
/**
* Multiple errors in a row.
*/
protected function try(int $count = 0) {
// @phpstan-ignore-next-line
$a['nonexisting_key'] = $b[$count];
if ($count < 50) {
$this->try($count + 1);
}
}
/**
* Try to reproduce Rollbar OOM error.
*/
public function build() {
// phpcs:disable
// @phpstan-ignore-next-line
$node = \Drupal::entityTypeManager()->getStorage('node')->load(1);
// phpcs:enable
$this->try();
return [
// @phpstan-ignore-next-line
'#markup' => '<pre class="rollbar-error">' . $a . $this->debug($node) . '</pre>',
];
}
}