From 4d5cb21360cf038fc6358bf35fc5d3bfe7091357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Correa=20Casablanca?= Date: Thu, 26 Oct 2017 12:21:25 +0200 Subject: [PATCH] Fix bug: now fatal errors don't crash the kernel --- src/Actions/ExecuteAction.php | 38 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Actions/ExecuteAction.php b/src/Actions/ExecuteAction.php index 76134b4..ed98536 100644 --- a/src/Actions/ExecuteAction.php +++ b/src/Actions/ExecuteAction.php @@ -119,27 +119,22 @@ private function getClosure(): callable $this->shellSoul->writeReturnValue($_); } catch (BreakException $_e) { - restore_error_handler(); - if (ob_get_level() > 0) { - ob_end_clean(); - } - $this->shellSoul->writeException($_e); - + $this->handleEvalException($_e); return; } catch (ThrowUpException $_e) { - restore_error_handler(); - if (ob_get_level() > 0) { - ob_end_clean(); - } - $this->shellSoul->writeException($_e); - + $this->handleEvalException($_e); throw $_e; + } catch (\Error $_e) { + $this->handleEvalException(new \ErrorException( + $_e->getMessage(), + $_e->getCode(), + 1, + $_e->getFile(), + $_e->getLine(), + $_e->getPrevious() + )); } catch (\Exception $_e) { - restore_error_handler(); - if (ob_get_level() > 0) { - ob_end_clean(); - } - $this->shellSoul->writeException($_e); + $this->handleEvalException($_e); } $this->shellSoul->setScopeVariables(get_defined_vars()); @@ -147,4 +142,13 @@ private function getClosure(): callable return $closure; } + + private function handleEvalException(\Exception $_e) + { + restore_error_handler(); + if (ob_get_level() > 0) { + ob_end_clean(); + } + $this->shellSoul->writeException($_e); + } }