From ee1a6c20d7d2d44c61258f56e17081893472d93f Mon Sep 17 00:00:00 2001 From: Bryan Davis Date: Thu, 16 May 2024 17:27:08 -0600 Subject: [PATCH] Pygmentize: report stderr when exit code != 0 and stdout is empty Most python error messages are reported to stderr rather than stdout. In the event of a catastrophic failure executing the Pygments binary we are likely to need to report stderr so that folks can debug the problem with the executable. Bug: T364249 Change-Id: Id5e5dbc515fdcdeb6eec61aacbbb9cbeddc79fab --- includes/Pygmentize.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/Pygmentize.php b/includes/Pygmentize.php index a240fcc8..831ef3a5 100644 --- a/includes/Pygmentize.php +++ b/includes/Pygmentize.php @@ -298,7 +298,11 @@ class Pygmentize { $output = $result->getStdout(); if ( $result->getExitCode() != 0 ) { - throw new PygmentsException( $output ); + if ( $output === "" || $output === null ) { + // Stdout was empty, report stderr instead + $output = $result->getStderr(); + } + throw new PygmentsException( (string)$output ); } return $output;