From c8072bccc583974740d80db71b04d8267dcbffba Mon Sep 17 00:00:00 2001 From: SjonHortensius Date: Thu, 25 Oct 2018 09:39:50 +0200 Subject: [PATCH] Prettify result for non-successful runs When a process exits with a non-zero code, replace HTML with text. [example here](https://chat.stackoverflow.com/transcript/message/44377825#44377825) --- src/Plugins/EvalCode.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Plugins/EvalCode.php b/src/Plugins/EvalCode.php index c41b2d8..9c512f3 100644 --- a/src/Plugins/EvalCode.php +++ b/src/Plugins/EvalCode.php @@ -99,7 +99,12 @@ private function getMessageText(string $title, string $output, string $url): str private function generateMessageFromOutput(array $output, string $url): string { - return $this->getMessageText($output["versions"], htmlspecialchars_decode($output["output"]), $url); + $text = htmlspecialchars_decode($output["output"]); + + if (preg_match('~^(?P.*)
Process exited with code (?P\d+)\.$~s', $text, $m)) + $text = sprintf('%s (process exited with %s code %d)', $m['raw'], $m['errName'], $m['errCode']); + + return $this->getMessageText($output["versions"], $text, $url); } private function doEval(HttpRequest $request, Command $command): \Generator