|
23 | 23 | use OpenConext\EngineBlockBundle\Exception\Art; |
24 | 24 | use Psr\Log\LoggerInterface; |
25 | 25 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 26 | +use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; |
26 | 27 |
|
27 | 28 | define('ENGINEBLOCK_FOLDER_ROOT' , realpath(__DIR__ . '/../../') . '/'); |
28 | 29 | define('ENGINEBLOCK_FOLDER_LIBRARY' , ENGINEBLOCK_FOLDER_ROOT . 'library/'); |
@@ -235,8 +236,10 @@ public function reportError(Throwable $exception, $messageSuffix = '') |
235 | 236 | $log->log($severity, $message, $logContext); |
236 | 237 |
|
237 | 238 | // Store some valuable debug info in session so it can be displayed on feedback pages |
238 | | - @session_start(); |
239 | | - $this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception)); |
| 239 | + if($this->hasSession()) { |
| 240 | + // In CLI context, the session is not available |
| 241 | + $this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception)); |
| 242 | + } |
240 | 243 |
|
241 | 244 | // flush all messages in queue, something went wrong! |
242 | 245 | $this->flushLog('An error was caught'); |
@@ -420,6 +423,16 @@ public function getSession() |
420 | 423 | return $this->getDiContainer()->getSession(); |
421 | 424 | } |
422 | 425 |
|
| 426 | + public function hasSession(): bool |
| 427 | + { |
| 428 | + try { |
| 429 | + $this->getSession(); |
| 430 | + return true; |
| 431 | + } catch (SessionNotFoundException) { |
| 432 | + return false; |
| 433 | + } |
| 434 | + } |
| 435 | + |
423 | 436 | /** |
424 | 437 | * @return \EngineBlock_Application_DiContainer |
425 | 438 | */ |
|
0 commit comments