Skip to content

Commit 2c4b6c5

Browse files
committed
ExceptionHandler now adds the XML context when rendering page fails due to XSLT error.
1 parent f311e50 commit 2c4b6c5

1 file changed

Lines changed: 43 additions & 4 deletions

File tree

src/Lib/ExceptionHandler.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ private static function getDatabaseTrace($queries)
6363
(isset($query['execution_time']) ? $query['execution_time'] : null)
6464
);
6565
}
66-
6766
return $result;
6867
}
6968

@@ -98,14 +97,54 @@ public static function render($e)
9897
$output['debug'] = [
9998
'file' => $e->getFile(),
10099
'line' => $e->getLine(),
101-
'severity' => ($e instanceof Lib\ErrorException ? \GenericErrorHandler::$errorTypeStrings[$e->getSeverity()] : 'Fatal Error'),
102-
'code_trace' => (count($e->getTrace()) > 0 ? self::getCodeTrace($e->getTrace()) : null),
100+
'severity' => (
101+
$e instanceof Lib\ErrorException
102+
? \GenericErrorHandler::$errorTypeStrings[$e->getSeverity()]
103+
: 'Fatal Error'
104+
),
105+
'code_trace' => (
106+
count($e->getTrace()) > 0
107+
? self::getCodeTrace($e->getTrace())
108+
: null
109+
),
103110
'database_trace' => self::getDatabaseTrace($databaseDebug),
104111
];
112+
113+
// See of this is an XSLT error. If so, include the XML output
114+
// since that is what is most likely failing.
115+
if (
116+
$e instanceof \SymphonyErrorPage &&
117+
$e->getTemplateName() == 'xslt' &&
118+
isset($e->getAdditional()->proc)
119+
) {
120+
$err = $e->getAdditional()->proc->getError(false, true);
121+
if (isset($err['value']) && isset($err['value']['context'])) {
122+
$xml = $err['value']['context'];
123+
124+
// Convert double quotes into single quotes. This stops
125+
// JSON from escaping double quotes
126+
$xml = preg_replace("@\"@", "'", $xml);
127+
128+
// Convert tab characters into 2 spaces. We cannot display
129+
// control characters in JSON output.
130+
$xml = preg_replace("@\t@", " ", $xml);
131+
132+
// Split the XML into individual lines. This is because
133+
// any newline control characters will be escaped
134+
$xmlLines = preg_split("@[\r\n]@", $xml);
135+
136+
// Add each line of the XML to the output. Use a zero padded
137+
// line number for readablity.
138+
$output['debug']['context'] = [];
139+
foreach ($xmlLines as $n => $l) {
140+
$output['debug']['context'][sprintf('%04d', $n+1)] = $l;
141+
}
142+
}
143+
}
105144
}
106145

107146
// output and die
108-
echo json_encode($output, JsonFrontend::DEFAULT_ENCODING_OPTIONS);
147+
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
109148
exit(255);
110149
}
111150
}

0 commit comments

Comments
 (0)