diff --git a/src/parser/xhpast/api/XHPASTTree.php b/src/parser/xhpast/api/XHPASTTree.php
--- a/src/parser/xhpast/api/XHPASTTree.php
+++ b/src/parser/xhpast/api/XHPASTTree.php
@@ -56,7 +56,7 @@
           $stderr,
           $matches);
         if ($is_syntax) {
-          throw new XHPASTSyntaxErrorException($matches[2], $stderr);
+          throw new XHPASTSyntaxErrorException($matches[2], trim($stderr));
         }
       }
       throw new Exception("XHPAST failed to parse file data {$err}: {$stderr}");