PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
ThreadCrashInfo.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\thread;
25
26use pmmp\thread\ThreadSafe;
27use pmmp\thread\ThreadSafeArray;
31use function get_class;
32use function sprintf;
33
34final class ThreadCrashInfo extends ThreadSafe{
35
37 private ThreadSafeArray $trace;
38
42 public function __construct(
43 private string $type,
44 private string $message,
45 private string $file,
46 private int $line,
47 array $trace,
48 private string $threadName
49 ){
50 $this->trace = ThreadSafeArray::fromArray($trace);
51 }
52
53 public static function fromThrowable(\Throwable $e, string $threadName) : self{
54 return new self(get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), Utils::printableTraceWithMetadata($e->getTrace()), $threadName);
55 }
56
60 public static function fromLastErrorInfo(array $info, string $threadName) : self{
61 try{
62 $class = ErrorTypeToStringMap::get($info["type"]);
63 }catch(\InvalidArgumentException){
64 $class = "Unknown error type (" . $info["type"] . ")";
65 }
66 return new self($class, $info["message"], $info["file"], $info["line"], Utils::printableTraceWithMetadata(Utils::currentTrace()), $threadName);
67 }
68
69 public function getType() : string{ return $this->type; }
70
71 public function getMessage() : string{ return $this->message; }
72
73 public function getFile() : string{ return $this->file; }
74
75 public function getLine() : int{ return $this->line; }
76
80 public function getTrace() : array{
81 return (array) $this->trace;
82 }
83
84 public function getThreadName() : string{ return $this->threadName; }
85
86 public function makePrettyMessage() : string{
87 return sprintf("%s: \"%s\" in \"%s\" on line %d", $this->type ?? "Fatal error", $this->message, Filesystem::cleanPath($this->file), $this->line);
88 }
89}
static fromLastErrorInfo(array $info, string $threadName)
__construct(private string $type, private string $message, private string $file, private int $line, array $trace, private string $threadName)