Skip to content

Commit 2b4c48a

Browse files
Init: Use fallback plain text responder in worst case to report ilCtrl error
(cherry picked from commit fe44510)
1 parent 9bd86a1 commit 2b4c48a

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

components/ILIAS/Init/resources/ilias.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121
use ILIAS\HTTP\StatusCode;
2222
use ILIAS\Data\Factory as DataFactory;
2323
use ILIAS\Init\ErrorHandling\Http\ErrorPageResponder;
24+
use ILIAS\Init\ErrorHandling\Http\PlainTextFallbackResponder;
2425

2526
if (!file_exists('../ilias.ini.php')) {
2627
die('The ILIAS setup is not completed. Please run the setup routine.');
2728
}
2829

2930
require_once '../vendor/composer/vendor/autoload.php';
30-
require_once __DIR__ . '/../artifacts/bootstrap_default.php';
31-
entry_point('ILIAS Legacy Initialisation Adapter');
3231

3332
/** @var \ILIAS\DI\Container $DIC */
3433
global $DIC;
3534

3635
try {
36+
require_once __DIR__ . '/../artifacts/bootstrap_default.php';
37+
entry_point('ILIAS Legacy Initialisation Adapter');
38+
3739
$DIC->ctrl()->callBaseClass();
3840
} catch (ilCtrlException $e) {
3941
if (defined('DEVMODE') && DEVMODE) {
@@ -50,16 +52,24 @@
5052
$df->uri(ILIAS_HTTP_PATH . '/ilias.php?baseClass=ilRepositoryGUI')
5153
);
5254

53-
new ErrorPageResponder(
54-
$DIC->globalScreen(),
55-
$DIC->language(),
56-
$DIC->ui(),
57-
$DIC->http()
58-
)->respond(
59-
$DIC->language()->txt('http_404_not_found'),
60-
StatusCode::HTTP_NOT_FOUND,
61-
$back_target
62-
);
55+
try {
56+
new ErrorPageResponder(
57+
$DIC->globalScreen(),
58+
$DIC->language(),
59+
$DIC->ui(),
60+
$DIC->http()
61+
)->respond(
62+
$DIC->language()->txt('http_404_not_found'),
63+
StatusCode::HTTP_NOT_FOUND,
64+
$back_target
65+
);
66+
} catch (Throwable) {
67+
new PlainTextFallbackResponder()->respond(
68+
$e,
69+
StatusCode::HTTP_NOT_FOUND,
70+
$DIC->language()->txt('http_404_not_found')
71+
);
72+
}
6373
}
6474

6575
$DIC['ilBench']->save();

components/ILIAS/Init/src/ErrorHandling/Http/PlainTextFallbackResponder.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ class PlainTextFallbackResponder
5454
* @param int $status_code HTTP status code (default: 500).
5555
* @throws Throwable in DEVMODE
5656
*/
57-
public function respond(Throwable $e, int $status_code = StatusCode::HTTP_INTERNAL_SERVER_ERROR): never
58-
{
59-
if (defined('DEVMODE') && DEVMODE) {
57+
public function respond(
58+
Throwable $e,
59+
int $status_code = StatusCode::HTTP_INTERNAL_SERVER_ERROR,
60+
?string $status_message = null
61+
): never {
62+
if (\defined('DEVMODE') && DEVMODE) {
6063
throw $e;
6164
}
6265

@@ -65,12 +68,13 @@ public function respond(Throwable $e, int $status_code = StatusCode::HTTP_INTERN
6568
header('Content-Type: text/plain; charset=UTF-8');
6669
}
6770

68-
$incident_id = session_id() . '_' . (new \Random\Randomizer())->getInt(1, 9999);
71+
$session_prefix = session_id() !== '' ? session_id() : 'no-session';
72+
$incident_id = $session_prefix . '_' . (new \Random\Randomizer())->getInt(1, 9999);
6973
$timestamp = (new DateTimeImmutable())
7074
->setTimezone(new DateTimeZone('UTC'))
7175
->format('Y-m-d\TH:i:s\Z');
7276

73-
echo "Internal Server Error\n";
77+
echo ($status_message ?? 'Internal Server Error') . "\n";
7478
echo "Incident: $incident_id\n";
7579
echo "Timestamp: $timestamp\n";
7680

@@ -80,11 +84,12 @@ public function respond(Throwable $e, int $status_code = StatusCode::HTTP_INTERN
8084
echo "Message: {$e->getMessage()}\n";
8185
}
8286

83-
error_log(sprintf(
87+
error_log(
88+
\sprintf(
8489
"[%s] INCIDENT %s — Uncaught %s: %s in %s:%d\nStack trace:\n%s\n",
8590
$timestamp,
8691
$incident_id,
87-
get_class($e),
92+
\get_class($e),
8893
$e->getMessage(),
8994
$e->getFile(),
9095
$e->getLine(),

0 commit comments

Comments
 (0)