Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 4d5cb21

Browse files
author
Andrés Correa Casablanca
committed
Fix bug: now fatal errors don't crash the kernel
1 parent b88db3a commit 4d5cb21

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/Actions/ExecuteAction.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,32 +119,36 @@ private function getClosure(): callable
119119

120120
$this->shellSoul->writeReturnValue($_);
121121
} catch (BreakException $_e) {
122-
restore_error_handler();
123-
if (ob_get_level() > 0) {
124-
ob_end_clean();
125-
}
126-
$this->shellSoul->writeException($_e);
127-
122+
$this->handleEvalException($_e);
128123
return;
129124
} catch (ThrowUpException $_e) {
130-
restore_error_handler();
131-
if (ob_get_level() > 0) {
132-
ob_end_clean();
133-
}
134-
$this->shellSoul->writeException($_e);
135-
125+
$this->handleEvalException($_e);
136126
throw $_e;
127+
} catch (\Error $_e) {
128+
$this->handleEvalException(new \ErrorException(
129+
$_e->getMessage(),
130+
$_e->getCode(),
131+
1,
132+
$_e->getFile(),
133+
$_e->getLine(),
134+
$_e->getPrevious()
135+
));
137136
} catch (\Exception $_e) {
138-
restore_error_handler();
139-
if (ob_get_level() > 0) {
140-
ob_end_clean();
141-
}
142-
$this->shellSoul->writeException($_e);
137+
$this->handleEvalException($_e);
143138
}
144139

145140
$this->shellSoul->setScopeVariables(get_defined_vars());
146141
};
147142

148143
return $closure;
149144
}
145+
146+
private function handleEvalException(\Exception $_e)
147+
{
148+
restore_error_handler();
149+
if (ob_get_level() > 0) {
150+
ob_end_clean();
151+
}
152+
$this->shellSoul->writeException($_e);
153+
}
150154
}

0 commit comments

Comments
 (0)