22declare(strict_types=1);
24namespace pocketmine\thread;
26use pmmp\thread\ThreadSafe;
27use pmmp\thread\ThreadSafeArray;
31use
function get_class;
37 private ThreadSafeArray $trace;
44 private string $message,
48 private string $threadName
50 $this->trace = ThreadSafeArray::fromArray($trace);
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);
63 }
catch(\InvalidArgumentException){
64 $class =
"Unknown error type (" . $info[
"type"] .
")";
66 return new self($class, $info[
"message"], $info[
"file"], $info[
"line"], Utils::printableTraceWithMetadata(Utils::currentTrace()), $threadName);
69 public function getType() : string{ return $this->type; }
71 public function getMessage() : string{ return $this->message; }
73 public function getFile() : string{ return $this->file; }
75 public function getLine() : int{ return $this->line; }
81 return (array) $this->trace;
84 public function getThreadName() : string{ return $this->threadName; }
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);
static fromLastErrorInfo(array $info, string $threadName)
__construct(private string $type, private string $message, private string $file, private int $line, array $trace, private string $threadName)